Im Using a post query in wordpress BUT the Pagination is not working, i don’t know whats the problem BUT here is my code and i guess it’s correct and no problem with it
it shows that there is pages BUT when i Click on Next Page it refresh the page and don’t show any new results just the same page.
Im Using it on Static page to be The Home page of my theme
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$post_query = query_posts(array(
'post_type' => 'cover', // You can add a custom post type if you like
'paged' => $paged,
'posts_per_page' => 1
));
?>
<?php if ( have_posts() ) : ?>
<?php
while ( have_posts() ) : the_post();
?>
<?php endwhile; ?>
///Pagination Function in Functions.php
<?php my_pagination(); ?>
<?php else: ?>
No Results
<?php endif; ?>
Pagination Function
if ( ! function_exists( 'my_pagination' ) ) :
function my_pagination() {
global $wp_query;
$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') ),
'total' => $wp_query->max_num_pages
) );
}
endif;
This solution needs to be revised for that pagination functions are in functions.php.
I am using Reverie master theme (which uses foundation framework), that theme uses pagination function which is in functions.php
I have revised this function as
the variable $another_query is my custom WP_Query. This questions author used *query_posts* to get results but I have used *new WP_Query*.
And the query which I have used inside front-page is;
If you have multiple loops in same page (for ex. in front_page) , sometimes pagination gets broken.
I have solved problem by using same query name;
From above example we used
$myqueryis = $another_query;
and in function we used'total' => $myqueryis->max_num_pages,
and also I gived the query args and query like this;with second the loop example
and maybe with third the loop example
this is worked properly for page/1 page/2 page/…