Prabin Parajuli
Prabin Parajuli

Reputation: 559

posts_per_page not working on my Custom Post Type

I am trying to limit my posts from my custom post type but it's displaying all the posts. I want to limit the posts by 3. I've tried all the possible solutions from the Stackoverflow

Here's the code:

<?php   global $post;
            wp_reset_query();
            $args = array( 
            'posts_per_page' => 3, 
            'post_type' => 'services',
            'orderby' => 'date', 
            'order' => 'DESC', 
            'update_post_term_cache' => false, 
            'update_post_meta_cache' => false, 
            'nopaging' => true, 
        );
    $the_query = new WP_Query( $args ); ?>

Am I missing anything here?

Any suggestion will be appreciated !!

Upvotes: 0

Views: 6126

Answers (1)

wojtek.ww
wojtek.ww

Reputation: 145

posts_per_page is pagination parameter but by using 'nopaging' => true you disabled the pagination.

try this snippet instead

<?php   global $post;
        wp_reset_query();
        $args = array( 
        'posts_per_page' => 3, 
        'post_type' => 'services',
        'orderby' => 'date', 
        'order' => 'DESC', 
        'update_post_term_cache' => false, 
        'update_post_meta_cache' => false 
    );
    $the_query = new WP_Query( $args ); 
?>

For more details read section 'Pagination Parameters' in WordPress Codex

Upvotes: 5

Related Questions