0
votes

I have this wp_query but it only returns 1 post. I want it to return anything in the 'directory' category with the tag 'pick'. I know there can be problems with posts_per_page, but nothing is working (I've searched a lot) to get the query to display more than one post. Any help would be great.

<?php // The Query

            wp_reset_query();

            global $wp_query;

            $term = $wp_query->queried_object;

            $args=array(
                'ignore_sticky_posts' => true,
                'posts_per_page' => -1,
                'post_type' => 'directory',
                'suppress_filters' => true,
                'tag' => 'picks',
                'tax_query' => array(
                array(
                    'taxonomy'  => $term->taxonomy,
                    'field'     => 'slug',
                    'terms'     => $term->slug,
                    )
                )
            );

            $new_query = new WP_Query($args);

        if ( $new_query->have_posts()) : $new_query->the_post(); ?>

            <article <?php post_class('post-tile'); ?>>
                <a href="<?php the_permalink() ?>" rel="bookmark">
                <?php
                    $post_thumbnail_id = get_post_thumbnail_id( );
                    $imagesized = wp_get_attachment_image_src( $post_thumbnail_id, 'big-post-thumb');
                    if ($imagesized[1] == 308) {
                        the_post_thumbnail('big-post-thumb');
                    } else {
                        the_post_thumbnail('cat-post-thumb');
                    }
                ?>
                <h3><?php the_title(); ?></h3>
                <div class="intro">
                    <p><?php echo get_excerpt(140); ?></p>
                </div>
                </a>
            </article>
            <?php wp_reset_postdata(); else : ?>
            <p>No picks as yet&hellip;</p>
        <?php endif; ?>

    </div>
1

1 Answers

0
votes

The problem isn't with posts_per_page but rather the loop which is missing a crucial component. It doesn't have a while statment.

At the moment all your loop is doing is displaying the first post. You need the while statement in order to iterate through all of the posts.

Change this line:

if ( $new_query->have_posts()) : $new_query->the_post(); ?>

To this:

if ( $new_query->have_posts() ) : while ( $new_query->have_posts() ) : $new_query->the_post(); ?>

And this line:

<?php wp_reset_postdata(); else : ?>

To this:

<?php wp_reset_postdata(); endwhile; else : ?>