I did folowed the steps / solution from Jeff it helped me alot with he's settings, got it for about 90% working properly. But getting stuck on the post / postname. It loads now the producten/%taxonomy_products%/ without the 404 errors. But when i click further on a post i get the 404 errors again.

Maybe you can see what i'am doing wrong?

Custom post type and taxonomy settings 'Sorry for the dutch words' :

    add_action( 'init', 'products_taxonomy_options' );
function products_taxonomy_options() {

//=============== Register custom post type - PRODUCTS ================

  array( 'label'                    => __('Producten'), // Postype
         'labels'                   => array( 'name'                => __('Producten'),
                                              'singular_name'       => __('Producten'),
                                              'add_new'             => __('Product toevoegen'),
                                              'add_new_item'        => __('Nieuw product'),
                                              'edit_item'           => __('Wijzig product'),
                                              'new_item'            => __('Nieuw product'),
                                              'all_items'           => __('Alle producten'),
                                              'view_item'           => __('Bekijk producten'),
                                              'search_items'        => __('Zoek producten'),
                                              'not_found'           => __('Er zijn geen producten gevonden'),
                                              'not_found_in_trash'  => __('Geen producten gevonden in de prullenbak')                                   
          'public'                  => true,
          'can_export'              => true,
          'show_ui'                 => true,    // UI in admin panel
          '_builtin'                => false,   // It's a custom post type, not built in
          '_edit_link'              => 'post.php?post=%d',
          'capability_type'         => 'post',
          //'menu_icon'             => get_bloginfo('template_url').'/images/favicon.ico',
          'hierarchical'            => true,
          'rewrite'                 => array(   "slug" => "producten"), // Permalinks
          'supports'                => array(   'title',
          'show_in_menu'            => true,
          'taxonomies'              => array('productcat')

//=============== Register custom taxonomy - PRODUCTS CATEGORY ================ 

register_taxonomy(  "productcat", 
                array(  "products"  ), 
                array ( "hierarchical"      => true, 
                        "label"             => "Product categorieën", 
                        'labels'            => array(   'name'              => __('Product categorieën'),
                                                        'singular_name'     => __('Product categorie'),
                                                        'search_items'      => __('Categorieën zoeken'),
                                                        'popular_items'     => __('Populaire categorieën'),
                                                        'all_items'         => __('Alle categorieën'),
                                                        'parent_item'       => __('Huidige categorie'),
                                                        'parent_item_colon' => __('Huidige categorie:'),
                                                        'edit_item'         => __('Wijzig categorie'),
                                                        'update_item'       => __('Update categorie'),
                                                        'add_new_item'      => __('Nieuwe categorie toevoegen'),
                                                        'new_item_name'     => __('Nieuwe categorie')
                          'show_ui'         => false,
                          'query_var'       => true,
                          '_builtin'        => false,
                          'paged'           => true,
                          'rewrite'         => array(   'hierarchical'      => true, 
                                                        'slug'              =>'products',
                                                        'with_front'        => false


Jeff's settings:

add_filter('rewrite_rules_array', 'mmp_rewrite_rules');
function mmp_rewrite_rules($rules) {
    $newRules  = array();
    $newRules['producten/(.+)/(.+)/(.+)/(.+)/?$'] = 'index.php?products=$matches[4]'; // my custom structure will also have the post name as the 5th uri segment
    $newRules['producten/(.+)/?$']                = 'index.php?productcat=$matches[1]'; 

    return array_merge($newRules, $rules);

function filter_post_type_link($link, $post)
    if ($post->post_type != 'products')
        return $link;

    if ($cats = get_the_terms($post->ID, 'productcat'))
        $link = str_replace('%taxonomy_products%', get_taxonomy_parents(array_pop($cats)->term_id, 'productcat', false, '/', true), $link); // see custom function defined below
    return $link;
add_filter('post_type_link', 'filter_post_type_link', 10, 2);

// my own function to do what get_category_parents does for other taxonomies
function get_taxonomy_parents($id, $taxonomy, $link = false, $separator = '/', $nicename = false, $visited = array()) {    
    $chain = '';   
    $parent = &get_term($id, $taxonomy);

    if (is_wp_error($parent)) {
        return $parent;

    if ($nicename)    
        $name = $parent -> slug;        
        $name = $parent -> name;

    if ($parent -> parent && ($parent -> parent != $parent -> term_id) && !in_array($parent -> parent, $visited)) {    
        $visited[] = $parent -> parent;    
        $chain .= get_taxonomy_parents($parent -> parent, $taxonomy, $link, $separator, $nicename, $visited);


    if ($link) {
        // nothing, can't get this working :(
    } else    
        $chain .= $name . $separator;    
    return $chain;    

Permalink settings:


Working with the Taxonomic SEO Permalink plugin


  • Did you flush your rules?
    – kaiser
    Commented Mar 27, 2012 at 13:42
  • I dont realy know how i can flush the permalinks, because it needs to be done on theme activation? Or can i also just put it in the taxonomy build up? I tried it on this way link but the fields are empty or not visible in the database.
    – Reitze Bos
    Commented Mar 27, 2012 at 14:34
  • Just save your permalink settings once.
    – kaiser
    Commented Mar 27, 2012 at 14:39
  • Yes, i tried that also first with different settings, then tried it with the standard permalinks. When that is active i didnt get any errors and worked nice. But when i want to change back to the seo friendly permalinks structure i'm getting again the 404 error result but only on the post pages.
    – Reitze Bos
    Commented Mar 27, 2012 at 15:43

1 Answer 1


Thanks for referencing my solution. You forgot one part though - defining the rewrite of your cpt. From my solution:

First get your slugs right when defining your custom post types and taxonomies: for the custom post type it should be basename/%taxonomy_name% and the slug for your taxonomy should be just basename. Dont forget to also add 'hierarchical' => true to the taxonomy rewrite array to get nested terms in your url. Also make sure query_var is set to true in both cases.

So in your case your rewrite for your custom post type should be producten/%productcat%. Also it looks like in my filter_post_type_link function you need to change %taxonomy_products% to %productcat%.

Hopefully that will make it work!

  • Thanks changed that, but also didnt mentioned in the newRules he did skipped step 2. $newRules['producten/(.+)/(.+)/?$'] = 'index.php?products=$matches[2]'; $newRules['producten/(.+)/?$'] = 'index.php?productcat=$matches[1]';
    – Reitze Bos
    Commented Mar 29, 2012 at 10:32

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.