您的帖子类型是非层次式的帖子,还是层次式的页面?它将确定应该在中使用哪个slug参数WP_Query:
name (string) - non-hierarchical (post) slug.
pagename (string) - hierarchical (page) slug.
此外,tax\\u查询还应具有operator参数。可能的值为“IN”、“NOT IN”、“AND”。您应该将其设置为“AND”。这可能是一个解决方案:
$args = array(
\'post_type\'=>\'specialist\',
\'postname\' => \'test\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'type\',
\'field\' => \'slug\',
\'terms\' => \'therapist\',
\'operator\'=> \'AND\'
)
)
);
$specialists = new WP_Query($args);
如果它真的不起作用,那么您可以通过创建一个过滤函数来解决问题,将where子句添加到查询中
function filter_where( $where = \'\' ) {
// post_name
$where .= " AND $wpdb->posts.post_name = \'test\'";
return $where;
}
add_filter( \'posts_where\', \'filter_where\' );
$query = new WP_Query( $args );
remove_filter( \'posts_where\', \'filter_where\' );