Check post title if exists before posting programmatically
-
Hello,
for a couple days now, I’ve been trying to figure out a code that checks post title if it already exists before posting. This is what I have done now:
function postit() { $user_info = wp_get_current_user(); $title = $user_info->user_login; $page = get_page_by_title('$title'); if(!$page){ $my_post = array( 'post_title' => $title, 'post_content' => '[ratingz]', 'post_status' => 'publish', 'post_author' => $user_ID ); wp_insert_post( $my_post ); } }
I’m using logged in user as post title.
I think I’m not so far away but where is the problem?
Thanks.
- The topic ‘Check post title if exists before posting programmatically’ is closed to new replies.