我正在尝试让我的循环遍历与这些术语相关的帖子。当前没有输出任何内容。
<?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; ?>
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。
干杯