Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress:检查特定自定义帖子类型中是否存在slug_Php_Mysql_Wordpress - Fatal编程技术网

Php Wordpress:检查特定自定义帖子类型中是否存在slug

Php Wordpress:检查特定自定义帖子类型中是否存在slug,php,mysql,wordpress,Php,Mysql,Wordpress,我正在使用下面的代码来检查slug是否存在,但它正在搜索所有帖子类型,我只需要检查特定的自定义帖子类型 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; } el

我正在使用下面的代码来检查slug是否存在,但它正在搜索所有帖子类型,我只需要检查特定的自定义帖子类型

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;
    }
}
用法:

if (the_slug_exists($term)) :
    echo 'Ok';
endif;
是否可以修改此代码以仅搜索特定的自定义帖子类型

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;
    }
}
用法


你试过
其中post_name='“$post_name.”和post_type='“$post_type.”“
?谢谢@Chay22。这正是我需要的。请用这个片段作为答案回复,这样我就可以关闭这个线程了。
if (the_slug_exists($term,$type)) :
    echo 'Ok';
endif;