New answers tagged wp-insert-post
2
It seems like the crux of the question is this:
This causes the first 'if' condition to return TRUE and it inserts a
duplicate post.
Check for the post_name instead. That value is normalized to lowercase and dashes by sanitize_title_with_dashes so you won't have this issue. That value is also the one that WordPress enforces as unique, and the one ...
1
It's because within wp_insert_post current user capabilities are checked before adding the terms:
if ( current_user_can($taxonomy_obj->cap->assign_terms) )
wp_set_post_terms( $post_ID, $tags, $taxonomy );
to get around this, use wp_set_object_terms instead after wp_insert_post to add the terms:
$new_post = array(
'post_title' => ...
0
If you do $content = "something"; you are replacing the $content variable's value. If you want to append something to the current content, you'd need to do something like:
$content = 'initial content';
$content .= 'more content (notice the dot)';
In this case, if you want to append the image to some existing content you'd need to do:
$content = ...
Top 50 recent answers are included