Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

waltone57 on "Check post title if exists before posting programmatically"

$
0
0

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.


Viewing all articles
Browse latest Browse all 8245

Trending Articles