0

I'm trying to create a filter by taxonomy for a custom post type.

When I use the filter option it creates this URL which doesn't work: /projecten-test/?branche=industrie/page/2/.

But when I enter this url manually, it DOES work: /projecten-test/page/2/?branche=industrie

How can I accomplish this automaticly, should I change the method in which I add the php GET to the URL, of should I change the wp_rewrite on the bottom of this function:

// Use pagination on custom post type function paginate() { global $wp_query, $wp_rewrite;

$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
$pagination = array(
    'base' => @add_query_arg('page','%#%'),
    'format' => '',
    'total' => $wp_query->max_num_pages,
    'current' => $current,
    'show_all' => true,
    'type' => 'plain',
    'prev_text'    => __('« Vorige'),
    'next_text'    => __('Volgende »')
);
if ( $wp_rewrite->using_permalinks() ) $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );
if ( !empty($wp_query->query_vars['s']) ) $pagination['add_args'] = array( 's' => get_query_var( 's' ) );
echo paginate_links( $pagination );

}

3
  • when you click on a link to another page, how does WordPress know what term was chosen on the previous page? also- note that taxonomy names should not contain capital letters, and use pre_get_posts to modify main query, never use query_posts.
    – Milo
    Oct 11, 2013 at 18:08
  • I could store it in the URL using the php $_GET method, guess I should edit the wp_rewrite rule or something?
    – Remi
    Oct 11, 2013 at 18:15
  • I can see that it is in this part: $pagination = array( 'base' => @add_query_arg('page','%#%'), The page/2/ of the link is in this part, but the taxonomy seems to be added before the '[here]/page/2/' part...
    – Remi
    Oct 11, 2013 at 20:36

1 Answer 1

0

Well this seems to fix it. Not sure if this is the best way to do it so please enlighten me if I'm wrong:

By changing:

if ( $wp_rewrite->using_permalinks() ) $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );

to:

if ( $wp_rewrite->using_permalinks() ) $_SERVER['REQUEST_URI'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );

It's working. Now all I have to do is to create a fall back if you enter a taxonomy from page 4 to the new taxonomy on page 1.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.