我有一个自定义的职位类型称为“特许经营”。我有一个自定义的帖子类型分类法,称为“目录”,它按行业对特许经营进行排序。在我的网站上,我创建了一个简短的代码,在这里你可以向函数传递一个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');如果有人能提供任何线索,我将不胜感激。谢谢你。
发布于 2021-07-13 17:22:12
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');https://stackoverflow.com/questions/68359506
复制相似问题