Wordpress Tax_Query on Custom Post Type Term, Tax Query not



我有一个名为"特许经营";。我有一个自定义的帖子类型分类法,称为";目录";,按行业对特许经营进行分类。在我的网站上,我创建了一个快捷代码,在这里你可以向函数传递一个ID(相对于术语的ID(,就像这样

[CUSTOM_FRANCHISES term="8"]

我遇到的问题是,它没有按术语过滤。函数获取已发布的值,在上面的情况8中,我可以成功返回已发布的数值。当返回来自短代码的数据时,它会显示所有内容,而不会按术语进行筛选。

function custom_franchises($atts){
ob_start();
global $post;
$set_cat = $atts['term'];
$args = new wp_query(
array(
'post_status' => 'publish',
'post_type' => 'franchise',
'posts_per_page' => 5,
'tax_query' =>
array(
'taxonomy' => 'directory',
'field' => 'id',
'terms' => $set_cat,
)   
)
);      
while($args->have_posts()){
$args->the_post();
$post = get_post();
$postid = $post->ID;

$htmlcontent .= "<p>".$postid."</p>";
}
return $htmlcontent;
ob_end_clean();
}
add_shortcode('CUSTOM_FRANCHISES', 'custom_franchises');

如果有人能透露任何信息,我们将不胜感激。谢谢。

function custom_franchises($atts){
ob_start();
global $post;
$set_cat = $atts['term'];
$args = new wp_query(
array(
'post_status' => 'publish',
'post_type' => 'franchise',
'posts_per_page' => 5,
'tax_query' => array(
array(
'taxonomy' => 'directory',
'field' => 'term_id',
'terms' => array($set_cat),
)   
)
)
);      
while($args->have_posts()){
$args->the_post();
$post = get_post();
$postid = $post->ID;

$htmlcontent .= "<p>".$postid."</p>";
}
return $htmlcontent;
ob_end_clean();
}
add_shortcode('CUSTOM_FRANCHISES', 'custom_franchises');

最新更新