【问题标题】:Wordpress tax_query not showing private postsWordpress tax_query 不显示私人帖子
【发布时间】: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; ?>

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

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

    试试这个

    $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
    

    【讨论】:

      猜你喜欢
      • 2013-01-05
      • 1970-01-01
      • 2019-05-28
      • 2016-05-10
      • 1970-01-01
      • 1970-01-01
      • 2018-06-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多