WordPress.org

Support

Support » Themes and Templates » [Resolved] Rewriting slug for custom category points to attachment instead of category

[Resolved] Rewriting slug for custom category points to attachment instead of category

  • 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

    register_taxonomy(‘custom_category’,’custom_post_type’,array(‘label’=>’Category’,
    ‘labels’=>array(‘name’=>’Categories’,’singular_name’=>’Category’),
    ‘rewrite’=>array(‘slug’=>’section/subsection/category’,’with_front’=>false),
    //’query_var’=>true,
    ‘hierarchical’=>false));

    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.

    Thanks!
    Brittney

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.

    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’);

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Rewriting slug for custom category points to attachment instead of category’ is closed to new replies.