i would like to create a post from the front end of my wordpress site.
When people add posts with the same post_title i want that post to get updated, rather than creating a new post.
i have the following:
if (!get_page_by_title($post_title, 'OBJECT', 'post') ){
$my_post = array(
'post_title' => $post_title,
'post_content' => $post_content,
'post_status' => 'publish',
'post_author' => $post_author,
'post_category' => $post_categories
);
wp_insert_post( $my_post );
}
else {
$page = get_page_by_title($post_title);
$page_id = $page->ID;
$my_post = array(
'ID' => $page_id,
'post_title' => $post_title,
'post_content' => $post_content,
'post_status' => 'publish',
'post_author' => $post_author,
'post_category' => $post_categories
);
wp_update_post( $my_post );
}
the above works fine until the post title is the same. It will still duplicate in the database and wont even consider the "else" statement.
Does the above look ok, or am i doing something wrong?