Bru*_*iro 5 php mysql wordpress
我正在使用下面的代码检查是否存在子弹,但它正在搜索所有帖子类型,因此我只需要检查特定的自定义帖子类型。
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;
}
}
Run Code Online (Sandbox Code Playgroud)
用法:
if (the_slug_exists($term)) :
echo 'Ok';
endif;
Run Code Online (Sandbox Code Playgroud)
是否可以修改此代码以仅在特定的自定义帖子类型上进行搜索?
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;
}
}
Run Code Online (Sandbox Code Playgroud)
用法
if (the_slug_exists($term,$type)) :
echo 'Ok';
endif;
Run Code Online (Sandbox Code Playgroud)