I'm using the code below to check if a slug exists, but it's searching on all post types and I need to check only on a specific custom post type.
function the_slug_exists($post_name) {
global $wpdb;
if($wpdb->get_row("SELECT post_name FROM wp_posts WHERE post_name = '" . $post_name . "'", 'ARRAY_A')) {
return true;
} else {
return false;
}
}
Usage:
if (the_slug_exists($term)) :
echo 'Ok';
endif;
Is it possible to modify this code to search only on a specific custom post type?
function the_slug_exists($post_name, $post_type) {
global $wpdb;
if($wpdb->get_row("SELECT post_name FROM wp_posts WHERE post_name = '" . $post_name . "' AND post_type = '" . $post_type . "'", 'ARRAY_A')) {
return true;
} else {
return false;
}
}
Usage
if (the_slug_exists($term,$type)) :
echo 'Ok';
endif;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With