Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm experiencing a problem with the pagination of my custom taxonomies which lead to a 404 instead of the taxonomy-product_brand.php template

Here is some code:

add_action('init','init_product_brand_taxonomy');
function init_product_brand_taxonomy() {
    // Labels
    $labels = array(
        'name' => __('Product brands','framework'),
        'singular_name' => __('Product brand','framework'),
        'search_items' => __('Search a brand','framework'),
        'all_items' => __('All brands','framework'),
        'parent_item' => __('Parent brand','framework'),
        'parent_item_colon' => __('Parent brand:','framework'),
        'edit_item' => __('Edit brand','framework'), 
        'update_item' => __('Update brand','framework'),
        'add_new_item' => __('Add new brand','framework'),
        'new_item_name' => __('New brand','framework'),
        'menu_name' => __('Brands','framework')
    );
    // Arguments
    $args =  array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array('slug' => 'products/%product_category%')
    );
    // Register taxonomy
    register_taxonomy('product_brand',array('product'),$args);
}

and the function to replace the %product_category%:

add_filter('term_link', 'filter_term_link', 10, 2);
function filter_term_link($link, $category) {
    if ($cats = @get_the_terms($post->ID, 'product_brand'))
        $link = str_replace('%product_brand%', array_pop($cats)->slug, $link);

    if ($cats = @get_the_terms($post->ID, 'product_category'))
        $link = str_replace('%product_category%', array_pop($cats)->slug, $link);

    return $link;
}

The point is that when I'm trying to add the pagination (posts_per_page=5 for instance), wordpress throws a 404 page instead of the right template:

this page: /products/kits-batterie/agean is working

this page: /products/kits-batterie/agean/page/2 is not working

Have you got any idea ?

Thanks!

** UPDATE **

Interesting thing, I've got another taxonomy on which I thought the pagination what working because it's not nested in another taxonomy. I figured that it was working ONLY if there is no dash in the taxonomy name

For instance: /brands/abcde/page/2 is working when /brands/abc-de/page/2 is going to the 404 template.

share|improve this question
40% accept rate... – kaiser Sep 23 '11 at 13:02
I actually accept when someone answer correctly to my questions, 60% not the case – Cyril Sep 23 '11 at 15:26
How can someone help out if you don't comment on answers or just plain simple stop commenting? – kaiser Sep 23 '11 at 15:42

closed as too localized by toscho Jul 14 '12 at 21:32

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

In your taxonomy-product_brand.php do you have paged in your query?

example:

$query = new WP_Query( 'paged=' . get_query_var( 'page' ) );

Without that it will not display pages for your custom taxonomie.

share|improve this answer
Hi and thanks for your answer. This is not working, the template triggered is a 404 template (not the taxonomy-product_brand template) so I guess something is wrong in the rewrite rule – Cyril Sep 25 '11 at 11:11

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