使用自定义分类数组订购帖子

时间:2014-02-18 作者:davehudson52

我正在尝试让我的循环遍历与这些术语相关的帖子。当前没有输出任何内容。

<?php

    $args = array(
        \'post_type\' => \'staff\',
        \'posts_per_page\' => \'-1\',
        \'tax_query\' => array(
                array(
                    \'taxonomy\' => \'staff\',
                    \'field\' => \'slug\',
                    \'terms\' => array(
                                    \'editor-in-chief\',
                                    \'managing-editor\',
                                    \'fiction-editor\',
                                    \'poetry-editor\',
                                    \'nonfiction-editor\',
                                    \'production-manager\'
                                )
                )
            )
    );
    $my_query = new WP_Query( $args );

        if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post();
        ?>

                    <div class="loop four columns">
                        <div class="column-nest">
                            <h5 class="staff-title big-top-space"><?php the_field(\'staff_title\'); ?></h5>
                            <h6 class="staff-name  bottom-space"><?php the_field(\'staff_member_name\'); ?></h6>              
                        </div> <!-- column-nest -->
                        <figure class="staff-photo-border">
                            <img class="column-nest" src="<?php the_field(\'staff_member_photo\'); ?>" alt="photo of <?php the_field(\'staff_member_name\'); ?>" />
                        </figure> <!-- staff-photo-border -->
                    </div> <!-- loop four columns -->


        <?php the_content(); ?>
        <?php endwhile; endif; ?>

2 个回复
SO网友:toni_lehtimaki

使用has_term() 需要的名称taxonomy 作为参数。

参考文献:

SO网友:Jeffrey Carandang

您不必将循环用于术语。改用tax\\u查询。以下是codex链接:http://codex.wordpress.org/Class_Reference/WP_Query

您的参数应该是

    $args = array(
    \'post_type\' => \'staff\',
    \'posts_per_page\' => \'-1\',
    \'tax_query\' => array(
            array(
                \'taxonomy\' => \'taxonomy_slug\',
                \'field\' => \'slug\',
                \'terms\' => array(
                                \'editor-in-chief\',
                                \'managing-editor\',
                                \'fiction-editor\',
                                \'poetry-editor\',
                                \'nonfiction-editor\',
                                \'production-manager\'
                            )
            )
        )
);
将“taxonomy\\u slug”更改为右侧slug。

干杯

结束