Support » Plugins » Hacks » Hierarchical custom taxonomy permalink gives 404

Viewing 8 replies - 1 through 8 (of 8 total)
  • The code can be found here:

    I still didn’t fix this problem. Does anyone got a solution? I’ve tried working with plugins, but they didn’t support the hierarchical part.

    I’m looking for a solution to this as well.. Any luck?

    Interested in this as well.

    Looking to structure URLs like:

    Right now we are forced to use pages as the hierarchy, but looking to build out using custom taxonomies and custom post types.

    Any idea if this will be built out in the future?

    *bump* just ran into this as well.

    Have a custom post type and a custom taxonomy,
    and after navigating the taxonomy archives you end up
    at a URL with the post-type as the base of the permalink
    rather than the custom taxonomy. It works, but is ugly.

    The problem seems to be that the slug parameter for
    rewrite option to register_post_type is undocumented/
    does not support normal permalink variables…

    If you don’t need to support multiple taxonomies,
    including the WordPress native one for posts, it looks
    like this plugin might work: Taxonomic SEO permalinks/

    After a few dead ends and incomplete solutions, I finally have something. My hierarchy is a custom taxonomy followed by the slug for a custom post type, which is different from the OP’s query, but the terminating slug is all that really matters, and you can add additional depth/validation as needed.

    If you have a custom ‘widget’ type (with a rewrite slug of widget), and widgets are filed under ‘color’s, you can do the following:

    #Fix links for custom type widget to have colored permalink
    function custom_post_link($post_link, $id = 0){
      $post = get_post($id);
      if( is_object($post) &&
          $post->post_type == 'widget' &&
          $terms = wp_get_object_terms($post->ID, 'color') ){
          $color = 'color/'. $terms[0]->slug;
          #This turns the widget/slug link into color/$color/slug
          return preg_replace('/\bwidget\b/', $color, $post_link);
      return $post_link;
    add_filter('post_type_link', 'custom_post_link', 1, 3);
    #Create rule to check for posts in color, and pass the terminal slug to find the content
    #We discard the hierarchy information in the URL here, but you could pass it on if needed
    add_rewrite_tag("%color%", '([^/]+)');

    I finally have something


    How are you getting on with the solution you posted here ? Are there any caveats worth mentioning ?

    How would you write the code to achieve:


    The solution is working well.

    One caveat is that the permalink (if shown) under the title in the editor for saved drafts and posts is mangled, and the slug is not editable here after the first save; you can still quick edit it in the post listing. But otherwise no problems, and that’s minor enough (arguably cosmetic) to ignore in my case. This ought to be fixable, but I’ve not had the tuits to tackle it.

    As noted, only the terminal portion of the URI is important, which means the code ought to work for any depth. I vaguely recall having tested it with two levels and being fine.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Hierarchical custom taxonomy permalink gives 404’ is closed to new replies.