0
if ( have_posts() ) {
  while ( have_posts() ) {
    the_post();
    global $post;
    //loop here
  }
  if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
}

I have the following code in function as per the previous answer Pagination not working for category posts

add_action( 'pre_get_posts', function ( $q )
{
    if (    !is_admin() // Only target the front end queries
         && $q->is_main_query() // Targets the main query only
         && $q->is_category() // Only target category pages
    ) {
        $q->set( 'posts_per_page', 10 );
        $q->set( 'meta_key', 'custom_key' );
        $q->set( 'meta_value', '' );
        $q->set( 'meta_compare', '!=' );
        $q->set( 'orderby', 'meta_value_num' );
        $q->set( 'ignore_sticky_posts', 1 );
    }
});
3
  • That pre_get_posts action only works for category pages. If you need to include the search page, change && $q->is_category() to && ( $q->is_category() || $q->is_search() ). But still, I can't see how this is related :-) Jul 21, 2015 at 17:27
  • 'not working' - what is happening? what is not happening? what is wrong?
    – Michael
    Jul 21, 2015 at 17:43
  • Using above code Category, Search, Tags pagination is fine but ranking is not working. Jul 22, 2015 at 9:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.