I have done so much research this morning and I cannot find a solution to what is potentially a big problem. I’m trying to use wordpress pagination with a custom query and can’t seem to get it working!
Here is my code, Pagination just doesn’t show at all.
<?php //Template Name: Acapellas ?>
<?php get_header(); ?>
<div id="main-content">
<div class="container">
<div class="row">
<div class="col-md-3">
<?php get_sidebar('primary-left'); ?>
</div>
<div class="col-md-9">
<?php get_template_part( 'includes/ads', 'top' ); ?>
<div class="post-content">
<h1>Free Acapellas</h1>
<?php if (pmpro_hasMembershipLevel(array(1,2), $user_id)) { ?>
<?php echo do_shortcode('[collections]'); ?>
<?php } ?>
<?php
$args = array (
'post_type' => array( 'acapella' ),
'pagination' => true,
'posts_per_page' => '12',
'ignore_sticky_posts' => true,
);
// The Query
$query = new WP_Query( $args );
?>
<?php if ( $query->have_posts() ) : ?>
<ul class="acapellas row">
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<?php get_template_part( 'includes/list', 'acapella' ); ?>
<?php endwhile; ?>
</ul>
<?php // Previous/next page navigation.
the_posts_pagination( array(
'prev_text' => __( 'Previous page', '' ),
'next_text' => __( 'Next page', '' ),
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', '' ) . ' </span>',
) );
// If no content, include the "No posts found" template.
else :
get_template_part( 'content', 'none' );
endif;
?>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
Just download and install wp-pagenavi plugin and then use:
Pass your query object in wp_pagenavi method argument.
i guess, you are seeking a numbered pagination for custom query, than try this article
Kvcodes.
here is the code.
place the function on your current theme, functions.php
and use it on loop.php or index.php
and for the WP_Query example
that’s it.