Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • WP_Query for post pagination

    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 209
    Comment on it

    Here is the code to get your posts pagination. Here you give the number of posts which you want to print in the every page. Chang something according your custom post type or other.

        // WP_Query arguments
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $args = array (
            'post_type'              => 'news',     // Change according post type
            'post_status'            => 'publish',
            'pagination'             => true,
            'posts_per_page'         => '2',        // change according you.
            'paged'                  => $paged
        );
    
        // The Query
        $query = new WP_Query( $args );
    
        // The Loop
        if ( $query->have_posts() ) {
            while ( $query->have_posts() ) {
                $query->the_post();
                // do something
            }
            echo '';  
        } else {
            // no posts found
        }
    
        // Restore original Post Data
        wp_reset_postdata();    
    
    

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: