WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following structure:

  • Hotels (custom post type)

  • Continents (taxonomy)

Working actual links examples leading to single post: hotels/europe/france/a-hotel *hotels/europe/italy/firenze/a-hotel*

Problem: getting 404 when trying to access childs and grandchilds listings:

  • hotel/europe - works!
  • hotel/europe/france - 404
  • hotel/europe/france/paris - 404

Not sure if something is missing, should I use a page template for those access points?

The code was hard to get working, thanks for examples around here: http://pastebin.com/WYJLYjHM

Thanks for any help.

share|improve this question
up vote 1 down vote accepted

Solved by adding a filter and building the permalink. FIrt forget the pastebin code, just create a post type a nd the taxos you want, them add the filter:

add_filter('post_link', 'territorio_permalink', 10, 3);
add_filter('post_type_link', 'territorio_permalink', 10, 3);

function territorio_permalink($permalink, $post_id, $leavename) {
if (strpos($permalink, '%territorio%') === FALSE) return $permalink;

// Get post
$post = get_post($post_id);
if (!$post) return $permalink;

// Get taxonomy terms
$terms = wp_get_object_terms($post->ID, 'territorio');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0]))
$taxonomy_slug = $terms[0]->slug.'/'.$terms[1]->slug; //build here
else $taxonomy_slug = 'not-yet';

return str_replace('%territorio%', $taxonomy_slug, $permalink);

In post type creation use:

'rewrite' => array( 'slug' => 'anything-you-want/%territorio%','with_front' => false),

Note: if you want deeper links, your build should go deeper:

$taxonomy_slug = $terms[0]->slug.'/'.$terms[1]->slug.'/'.$terms[2]->slug;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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