【发布时间】:2014-09-14 23:14:17
【问题描述】:
使用以下内容查询帖子时:
$getClientsArgs = array(
'post_type' => 'client',
'showposts' => -1
);
query_posts($getClientsArgs);
如果查看者已登录,则会显示私人帖子。 否则,它会跳过该帖子并继续显示任何非私密帖子。
这是我期望的工作方式。
但是,当我开始使用 tax_query 时,私人帖子不会显示给登录或注销的人。它们根本不会被退回。
看这个例子:
$getClientsArgs = array(
'post_type' => 'client',
'showposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'client_types',
'field' => 'term_id',
'terms' => $clientType->term_id
)
)
);
query_posts($getClientsArgs);
编辑:
进一步检查似乎,当它不是上面的代码导致问题时。 请参阅第 3 行的评论。 它的代码:
<?php
$args = array(
'type' => 'client',
'hide_empty' => 0, //Setting this to 1 will cause the issue explained above
'hierarchical' => 1,
'taxonomy' => 'client_types'
);
$clientTypes = get_categories($args);
?>
<?php foreach ($clientTypes as $clientType): ?>
<h2><?php echo $clientType->name; ?></h2>
<div class="main clearfix">
<ul class="image-list">
<?php
$getClientsArgs = array(
'post_type' => 'client',
'showposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'client_types',
'field' => 'term_id',
'terms' => $clientType->term_id
)
)
);
query_posts($getClientsArgs);
?>
<?php while (have_posts()) : the_post(); ?>
<li>
<?php $workLink = get_field('linked_project'); ?>
<a href="<?php echo get_permalink($workLink[0]); ?>">
<img src="<?php the_field('logo'); ?>" />
</a>
</li>
<?php endwhile;
wp_reset_query(); ?>
</ul>
</div>
<?php endforeach; ?>
【问题讨论】: