0

I've created an taxonomy-regions.php template which displays all offers with the taxonomy.

$page = ( get_query_var('page') ) ? get_query_var('page') : 1;

$args = array(
  'post_type'=>'praca',
  'post_status' => 'publish',
  'posts_per_page' => 12,
  'paged' =>  $page,
  'tax_query' => array(
    array(
      'taxonomy' => $taxonomy,
      'field' => 'slug',
      'terms'   =>get_query_var('regions' )
      )
  )
);
$offers = new WP_Query( $args );

On the bottom there's a pagination function

<div  class='pagination'>
       <?php $big = 999999999;  echo str_replace('paged', 'page', paginate_links( array(
                  'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                  'format' => 'paged=%#%',
                  'current' => max( 1, get_query_var('page') ),
                  'total' => $offers->max_num_pages,
                  'prev_text'          => '<span class="dashicons dashicons-arrow-left-alt"></span>'.__('Previous'),
                  'next_text'          => __('Next').'<span class="dashicons dashicons-arrow-right-alt"></span>',
                ) ));
      ?>
    <?php endif; ?>
    </div>

Without the permalinks turned on the pagination works in the address bar there's

?regions=region_name&page=2

With permalinks turned on and on the second page, the structure looks

region/region_name/page/2

What am I missing?

This is what worked for me after some test and flushing rewrite rules, hope someone finds this helpful

add_action( 'init', 'region_rewrite' );
function region_rewrite()
{
    global $wp;
    $wp->add_query_var( 'section' );

    add_rewrite_rule(
      '^praca/region/([^/]*)/page/([0-9]+)/?',
      'index.php?regions=$matches[1]&page=$matches[2]',
      'top'
    );
}
  • It may be the issue of "endpoints". If I am not wrong you have register end-points to make it work. Please refer to this tutorial for understanding endpoint registration in WordPress. pmg.com/blog/… – BlueSuiter May 30 '17 at 11:50
  • Please use search. This question has been asked and answered here many times. – Milo May 30 '17 at 13:16
  • do you think I haven't? none of those solutions provided worked out for me :/ – adam May 30 '17 at 13:51
  • If you have, then you should show what you've tried. pre_get_posts is the correct solution in this case. – Milo May 30 '17 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.