[resolved] Rewriting slug for custom category points to attachment instead of category (3 posts)

  1. bkernan
    Posted 3 years ago #

    Hello and thanks for looking at my question,

    I'm having trouble with rewriting permalinks for a custom post type taxonomy.

    http://mysite.local/section/subsection/category/test/page/1/ points to the correct template. This is index.php?custom_category=test

    http://mysite.local/section/subsection/category/test/ - without the 'page/1/' - points to the 404 page. This is because its redirected ultimately to index.php?attachment=test


    I'm thinking this has to do with the order I've registered my custom taxonomies in? Though I have other custom categories for different custom post types, ex: custom_events, that works just fine.

    I'd greatly appreciate your feedback on similar experience.


  2. bkernan
    Posted 3 years ago #

    Removing this below solved the issue:

    global $wp_rewrite;
    $wp_rewrite->add_rewrite_tag("% custom_post_type%",'([^/]+)', "custom_post_type=");
    $wp_rewrite->add_permastruct('custom_post_type','/section/subsection/% custom_post_type%',false);

    But I need that to display cpt's in the under the custom section/subsection. Subsection is a cleaner name of the custom post type.

    Will post solution when found.

  3. bkernan
    Posted 3 years ago #

    Fixed!! Really hope this helps someone else.

    Updated the above code:

    global $wp_rewrite;
    $wp_rewrite->add_rewrite_tag("%custom_post_type%",'([^/]+)', "custom_post_type =");
    $wp_rewrite->add_permastruct('custom_post_type','/section/subsection/% custom_post_type%',false);

    $wp_rewrite->add_rewrite_tag("%custom_category%",'^section/subsection/category/([^/]+)', "custom_category=");
    add_rewrite_rule('^section/subsection/category/([^/]*)/?','index.php? custom_category=$matches[1]','top');

Topic Closed

This topic has been closed to new replies.

About this Topic