Wordpress tax_query没有显示私人帖子

时间:2014-07-23 16:33:57

标签: php wordpress

使用以下内容查询帖子时:

$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; ?>

1 个答案:

答案 0 :(得分:0)

您需要告诉查询显示私人帖子。默认情况下,只会公开公开信息。

试试这个

$getClientsArgs = array(
    'post_type' => 'client',
    'post_status' => array('publish', 'private');
    'showposts' => -1,
    'tax_query' => array(
        array(
            'taxonomy' => 'client_types',
            'field'    => 'term_id',
            'terms'    => $clientType->term_id
        )
    )
);

query_posts($getClientsArgs);

您还可以添加任何其他形式的帖子状态。

这些是可用选项

publish
pending    
draft
auto-draft
future
private
inherit
trash