I'm writing a plugin that takes an xml feed and posts it into WordPress using wp-cron
Everything is working dandy, except it keeps adding the same posts over again.
So, I'm working on a system to check to see if a post of that title already exists.
I've written this, but its always returning 'already exists'
global $wpdb;
$query = $wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_title = %s', $article->heading);
$wpdb->query( $query );
if ( $wpdb->num_rows ) {
error_log('already exists');
} else {
wp_insert_post($post, $wp_error);
}
I'm fairly new to working with the database side of WordPress and I saw the $wpdb when googling for help. Now, I haven't defined this anywhere but the place I was reading seemed to suggest it was built in.
All help appreciated!
Thanks