如何用逗号分隔分类术语,以便将其动态包含在税务查询中
我已经设法返回已为帖子选择的分类法,但是,这些分类法将作为一个附录列表返回,例如covid1covid2covid3
。我希望能够将这些covid1,covid2,covid3
(不返回最后一个逗号)将其分开,以便我可以在税务查询中使用它,该查询将根据这些分类法动态返回相关的帖子。在下面查看我的代码
$currentID = get_the_ID();
$post_terms = get_the_terms($currentID, 'vocabulary_1');
foreach ($post_terms as $post_term) {
$postTerm = $post_term->slug;
}
$args1 = array(
'post_type' => 'cme-education',
'posts_per_page' => '1',
'post_status' => 'publish',
'orderby'=>'rand',
'tax_query' => array(
array(
'taxonomy' => 'vocabulary_1',
'field' => 'slug',
'terms' => array($postTerm),
'operator' => 'IN',
'order' => 'ASC'
)
)
);
I have managed to return the taxonomies that have been selected for a post however, these are returned as one appended list eg covid1covid2covid3
. I want to be able to separate these out covid1, covid2, covid3
(not returning the last comma) so that I can use it in my tax query which would return related post dynamically based on these taxonomies. See my code below
$currentID = get_the_ID();
$post_terms = get_the_terms($currentID, 'vocabulary_1');
foreach ($post_terms as $post_term) {
$postTerm = $post_term->slug;
}
$args1 = array(
'post_type' => 'cme-education',
'posts_per_page' => '1',
'post_status' => 'publish',
'orderby'=>'rand',
'tax_query' => array(
array(
'taxonomy' => 'vocabulary_1',
'field' => 'slug',
'terms' => array($postTerm),
'operator' => 'IN',
'order' => 'ASC'
)
)
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题出在
$postTerm
中。首先将其设为数组:然后在其中存储术语,如下所示:
这是完整的代码:
The issue is in
$postTerm
. First make it array:then store terms in it, like this:
Here is the complete code: