1

When querying posts with the following:

$getClientsArgs = array(
    'post_type' => 'client',
    'showposts' => -1
);
query_posts($getClientsArgs);

Private posts are displayed if the person viewing is signed in. Else, it skips that post and proceeds to show any non-private posts.

This is how I expected it to work.

But, when I start using tax_query, private posts are not shown to either people logged in or logged out. They are not returned at all.

See this example:

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

query_posts($getClientsArgs);

EDIT:


Further inspection it seems that, when its not the code above causing the problem. See comment on line 3. Its this code:

<?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; ?>
  • Don't use query_posts, period. Use WP_Query. Go and have a look at the status parameters there as well. showposts is depreciated, should be using posts_per_page – Pieter Goosen Jul 24 '14 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.