繁体   English   中英

自定义帖子的双重分类过滤-Wordpress

[英]Double taxonomy filtering for custom posts - Wordpress

下面的代码返回为自定义分类法“ music_categories”(Rock,Jazz,Rap等)找到的所有tax_terms,然后将自定义帖子类型“ music”的所有帖子安排在相应的标题下。

但是我需要更多过滤。 帖子类型音乐具有第二种自定义分类法,称为“ portfolio”,其术语为“ Portfolio One”,“ Portfolio Two”和“ Portfolio Three”。

在下面的代码开始运行之前,我需要能够选择一个投资组合。

输出看起来像这样:

爵士乐

post1,post4,post10

岩石

post4,post5,post6

蓝调

post4,post10

等等...

        $post_type = 'music';
        $tax = 'music_categories';
        $tax_terms = get_terms($tax);

        if ($tax_terms) {
            foreach ($tax_terms as $tax_term) {
                $args=array(
                    'post_type' => $post_type,
                    "$tax" => $tax_term->slug,
                    'post_status' => 'publish',
                    'posts_per_page' => -1,
                    'caller_get_posts'=> 1
                    );

                $my_query = null;
                $my_query = new WP_Query($args);
                if( $my_query->have_posts() ) {
                    echo '<h1 class="taxonomy-heading">'. $tax_term->name . '</h1>';
                    while ($my_query->have_posts()) : $my_query->the_post(); ?>

                            // a post with given taxonomy (heading, paragraphs, images etc)

                    <?php
                    endwhile;
                }
                wp_reset_query();
            }
        }
        ?>

我在脑海中使这种方式变得更加复杂。 我在$ args数组中添加了一行,瞧!

                $args=array(
                    'post_type' => $post_type,
                    "$tax" => $tax_term->slug,
                    'portfolios' => 'portfolio-two',
                    'post_status' => 'publish',
                    'posts_per_page' => -1,
                    'caller_get_posts'=> 1
                    );

现在,我获得了来自后置类型音乐的所有帖子的列表,这些帖子被标记为作品二(分类法)。 他们根据其所属的流派分类法列出。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM