Firstly, I am a newbie when it comes to php. I have a plugin that periodically imports posts into my website. Normally, it should check if the post already exists, and if it does, it updates it. Otherwise it creates a new one. Now for some reason, it always takes the else
path no matter what.
The if
is like this:
if ( nmp_post_exists( $cam->username ) ) {
and the function is:
function nmp_post_exists($title) {
global $wpdb;
return $wpdb->get_row("SELECT * FROM wp_posts WHERE post_title = '" . $title . "'", 'ARRAY_A');
}
get_page_by_title()
, which, despite havepage
in its name, allows you to specify thepost_type
as a parameter (so you can searchpost
s as well as any custom post type).wp_
?