1

Hi i have this wordpress site and the pages will display images on it. Now my problem is when i add post_per_page => '50' then when i refresh the page the number of posts per page is not rendering correctly. Here is my code below.

<?php 
                        query_posts( array(
                        'post_per_page'  => 50,
                        'cat'=> '7',
                        'order' => 'ASC'
                    ) );

                ?>
                <?php while(have_posts()) : the_post(); ?>

                <div class="single-gallery anim-5-all interoors masonryImage mix span-4">
                    <div class="img-holder">
                        <?php
                            $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium' );
                            $url = $thumb['0'];
                        ?>
                        <img src="<?=$url; ?>" alt="">

                    </div>
                </div><!-- /.single-gallery -->
                <?php endwhile; wp_reset_query(); ?>

Now it will display 9 images on the page. Can someone help me figured this thing out? Any help is muchly appreciated. TIA

1 Answer 1

1

For a first, I fond mistake in your query arguments

'post_per_page'  => 50,

There is no such argument for wp_query loop use instead it

'posts_per_page'  => 50,

For a second there is quote from a wodpress codex about query_posts function

Note: This function will completely override the main query and isn’t intended for use by plugins or themes. Its overly-simplistic approach to modifying the main query can be problematic and should be avoided wherever possible. In most cases, there are better, more performant options for modifying the main query such as via the ‘pre_get_posts’ action within WP_Query.

I can recomend you to use standard wordpress loop

<?php
$args = [
    'posts_per_page' => 50,
    'cat'            => '7',
    'order'          => 'ASC',
];

// The Query
$query = new WP_Query( $args );

// The Loop


while ( $query->have_posts() ) : $query->the_post(); ?>
    <div class="single-gallery anim-5-all interoors masonryImage mix span-4">
        <div class="img-holder">
            <?php
                $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium' );
                $url = $thumb['0'];
            ?>

            <img src="<?=$url; ?>" alt="">

        </div>
    </div><!-- /.single-gallery -->
    <?php
endwhile;
wp_reset_postdata();
?>
1
  • 1
    Thank you. I just use this one query_posts with posts_per_page Commented Feb 14, 2018 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.