dimanche 19 mars 2017

WordPress - WP_Query do not load specifed number of post

I have on my page section with randomly selected posts via new WP_Query. The problem is that 'posts_per_page' attribute don't work. Here is my code:

<div id="featured">
    <?php 

        $args = array(
            'post_type' => 'post',
            'orderby'   => 'rand',
            'posts_per_page' => 4,
            'nopaging' => true,
            );

        $the_query = new WP_Query( $args );
        if ( $the_query->have_posts() ) {

            echo '<div style="table full">';

            while ( $the_query->have_posts() ) {

                $the_query->the_post(); 

            ?>

                <div class="featcell" style="background: url(<?php the_post_thumbnail_url(); ?>) center center">
                    <a class="featartlink" href="<?php echo get_permalink(); ?>"><?php echo get_the_title(); ?></a>
                </div>

            <?php 

            }

            echo '</div>';

            wp_reset_postdata();

        } 

    ?>
</div>

The result of script above is that script loading all posts from database. Script is placed under post on single post page. What i doing wrong? It appears that all is OK, but it is not! Thank You for help.




Aucun commentaire:

Enregistrer un commentaire