M
M
Marina Lebedeva2016-02-15 18:49:14
WordPress
Marina Lebedeva, 2016-02-15 18:49:14

Customizing Wp-pagenavi in ​​category.php with custom WP_Query loop?

There is a category.php that perfectly displays a list of products from its category + additional parameters.
WP-pagenavi renders pagination with the correct number of pages, but, systemically, wordpress only sees 2 pages.
The rest - in 404.
Has anyone encountered such a problem?
PS In pages, wp-pagenavi works flawlessly.
Output code:

<?php
global $paged;
if ( get_query_var('paged') )
  $my_page = get_query_var('paged');
else {
  if ( get_query_var('page') )
    $my_page = get_query_var('page');
  else
    $my_page = 1;
  set_query_var('paged', $my_page);
  $paged = $my_page;
}
$args = array(
  'tax_query'      => array(
    'relation' => 'AND',
    array(
      'taxonomy' => 'category',
      'field'    => 'id',
      'terms'    => array($cat_ID)
    )
  ),
  'post_type'      => 'post',
  'posts_per_page' => 5,
  'paged'          => $my_page
);
if ( $get_brand ) {
  $args['tax_query'][] = array(
    'taxonomy' => 'category',
    'field'    => 'slug',
    'terms'    => array($get_brand)
  );
}
$posts = new WP_Query($args);
if ( $posts->have_posts() ) :
  echo '<ul class="type-product__list">';
  while ( $posts->have_posts() ) :
    $posts->the_post();
// LOOP
    endwhile;
if(function_exists('wp_pagenavi')) {
  wp_pagenavi(array('query' => $posts));
  $wp_query = null;
  $wp_query = $posts;
}
  wp_reset_query();
  wp_reset_postdata();
endif;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Marina Lebedeva, 2016-02-16
@Margo_shka

The issue was resolved.
For correct work wp_page_nave should be post_per_page=10. Other values ​​in category.php are not accepted.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question