在一个循环内具有术语的多个分类法

时间:2016-09-23 22:36:20

标签: php arrays wordpress

下面的代码现在正在运行,问题由它解答。

我正在使用Wordpress网站,该网站上有两个分类法和未知数量的术语,都链接到自定义帖子类型。但是,只能选择一个术语进行分类。

基本上它看起来像这样: site.com/cpt/tax1/term/tax2/term。 在本周的大部分时间里,我一直在尝试拥有一个存档文件,该文件只能显示用户过滤的帖子,如上例所示:tax1有此术语,tax2有该术语。一个术语页面通过检索术语ID正常工作,然后查询正在使用它们。

然而,在存在两种分类法的情况下,该解决方案不会产生任何结果。以下是我一直在尝试使用的内容:

$term_list = wp_get_post_terms($post->ID, 'tax1', 'term_id');
$termID = $term_list[0]->term_id;
$term_list_pro = wp_get_post_terms($post->ID, 'tax2', 'term_id');
$termID_pro = $term_list_pro[0]->term_id;
$the_query = new WP_Query(array(
    'post_type' => 'cpt',
    'post_parent' => 0,
    'tax_query' => array(
    'relation' => 'AND',
        array(
            'taxonomy' => 'tax1',
            'terms' => $termID,
        ),
        array(
            'taxonomy' => 'tax2',
            'terms' => $termID_pro,
        )
    )
)); 

非常感谢任何帮助或指针,因为这非常高于我的技能水平。谢谢。

0 个答案:

没有答案