I have a custom post type named "tours" and a custom taxonomy named "tour_type".

"tour-type" taxonomy is hierarchical. In "tour-type" taxonomy, parent terms are limited to "eco-tours", "daily-tours", "package-tours" & "tailor-made-tours". All terms except "tailor-made-tours", have children.

I'm trying to reach a permalink structure like below for my tour post type:

/parent-tax/child-tax(if exist)/custom-post-type-name

For example it would end up like this:


Or like this (for "tailor-made-tours"):


I read lots of tutorials and solutions which lead me to these parts of code:

$tours_args = array(
    'labels'                => $tours_labels, //Some Labels
    'public'                => true,
    'menu_position'         => 10,
    'query_var'             => true,
    'rewrite'               => array('slug'=>'%tour_type%'),
    'supports'              => $custom_post_types_supports,
    'hierarchical'          => true,

add_filter('post_type_link', 'filter_post_type_link', 10, 2);
function filter_post_type_link($link, $post)
    if ($post->post_type == 'tours')
        Some codes which make $term equal to "parent-tax/child-tax"

        $link = str_replace('%tour_type%', $term, $link);
    return $link;

add_filter('rewrite_rules_array', 'mmp_rewrite_rules');
function mmp_rewrite_rules($rules) {
    $newRules  = array();

    $newRules['eco-tours/(.+)/(.+)/?$']         = 'index.php?post_type=tours&tour_types=eco-tours&custom_post_type_name=$matches[2]';
    $newRules['daily-tours/(.+)/(.+)/?$']       = 'index.php?post_type=tours&tour_types=daily-tours&custom_post_type_name=$matches[2]';
    $newRules['package-tours/(.+)/(.+)/?$']     = 'index.php?post_type=tours&tour_types=package-tours&custom_post_type_name=$matches[2]';
    $newRules['tailor-made-tours/(.+)/?$']      = 'index.php?post_type=tours&tour_types=tailor-made-tours&custom_post_type_name=$matches[1]';

    return array_merge($newRules, $rules);

Now, permalinks which are shown in post type edit pages, are showing the right url, but when I open each of them, they show an archive page of "tour" post type...

What did I drop in my codes?! :(

  • do you have a single-tour.php template? See more here : codex.wordpress.org/Template_Hierarchy – Laxmana Jun 12 '14 at 13:17
  • @Laxmana , I just made one, but it didn't work... The problem is that wordpress behave these urls as taxonomy archive page, not a single post page. – Yashari Jun 12 '14 at 13:29
  • Please try to save your permalinks structure(Settings -> Permalinks) and try again. – Laxmana Jun 12 '14 at 13:47
  • oh I just saw that your custom post name is being called tours and no tour. So the file should be single-tours.php. It's single-mycustompostname.php – Laxmana Jun 12 '14 at 13:49
  • @Laxmana Still not working... :( – Yashari Jun 12 '14 at 14:01

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.