0

This question already has an answer here:

I am trying to show all published posts of my custom post type and I wrote this $query = new WP_Query(array( 'post_type' => 'x-video', 'post_status' => 'publish', 'posts_per_page' => -1 )); /loop code/ pagenavi();

This query is retrieving all published posts at once and I am looping through the results and displaying one page.

What I need is, I want it to be paginated with 12 posts per page. How can I do that?

If I put 'posts_per_page' => 5 then it is showing only 5 posts but not pagination

marked as duplicate by fuxia Jul 28 '17 at 6:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

-1
<?php 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$news= new WP_Query(array(
    'post_type'=>'post',
    'posts_per_page' => 3,
    'paged' => $paged,
));

if($news->have_posts()) :
    while($news->have_posts())  : $news->the_post();
            the_title();
    endwhile;

    $total_pages = $news->max_num_pages;

    if ($total_pages > 1){

        $current_page = max(1, get_query_var('paged'));

        echo paginate_links(array(
            'base' => get_pagenum_link(1) . '%_%',
            'format' => '/page/%#%',
            'current' => $current_page,
            'total' => $total_pages,
            'prev_text'    => __('« prev'),
            'next_text'    => __('next »'),
        ));
    }
    ?>    
<?php else :?>
<h3><?php _e('404 Error&#58; Not Found', ''); ?></h3>
<?php endif; ?>
<?php wp_reset_postdata();?>
-1
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                $args_blog = array(
                'post_type' => ''x-video',
                'paged' => $paged,
                'posts_per_page' => 5
                );
                $query_blog = new WP_Query( $args_blog );
                if($query_blog->have_posts()) : while($query_blog->have_posts()) : $query_blog->the_post();
           ?>
                       <div class="pagination">
                           <?php
                    $big = 999999999; // need an unlikely integer
                    echo paginate_links( array(
                'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                'format' => '?paged=%#%',
                'current' => max( 1, get_query_var('paged') ),
                'prev_text'          => __('Prev'),
                'next_text'          => __('Next'),
                'total' => $query_blog->max_num_pages
            ) );
            ?> 
                        </div>
                        <?php
                else :
                    get_template_part( 'content', 'none' );
                endif;
                ?>
  • Please try above code and check its working code. – Vishit Jul 28 '17 at 6:43

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