• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Custom Taxonomy URL

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Custom Taxonomy URL

This topic is: resolved

Tagged: api, custom, post, rewrite, structure, taxonomy, type, URL

  • This topic has 9 replies, 2 voices, and was last updated 10 years, 7 months ago by Porter.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • April 4, 2015 at 1:42 pm #146682
    Porter
    Participant

    I have a structure like so:

    Dining - (Custom Post Type)

    dining_types (Custom Taxonomy belonging to Dining Custom Post Type)

    -restaurants (term)
    -cafes (term)
    -delis (term)
    -street-vendors (term)

    I'm trying to programmatically assign custom templates for the following:

    -Custom Post Type (Dining) site.com/dining
    -Terms of dining_types custom taxonomy (Restaurants) site.com/dining/restaurants (desired url)

    I've got the conditional check to assign the template (here's a piece of it)

    function anib_taxonomy_templates( $original_template ) {
     if (is_post_type('dining')) {
        return get_stylesheet_directory_uri() .  '/custom-templates/template-test.php';
      } else {
        return $original_template;
      }
    }
    
    add_filter( 'template_include', 'anib_taxonomy_templates' );

    I know have to use is_tax for the terms. That being said, I can't even find the archive page for the terms. I thought it would be site.com/dining/term-name, or site.com/dining/custom-taxonomy-name/term-name, but it's not at either. I have no idea what url it's at, and more importantly, I need to MAKE it the way I want it using the rewrite API (I assume). To the best of my knowledge, my structure perfectly matches that of the default category / tag structure, and I should be able to get this working. I will have other custom post types and taxonomies, but if I can get one working, I should be able to get them all.

    I would love a helping hand in sorting this out, as I'm at a loss and 20 tabs open isn't leading me to what I need.


    Buy me a beer? | Try DigitalOcean VPS Hosting

    April 4, 2015 at 3:30 pm #146688
    Porter
    Participant

    So I found the url the term is currently at - site.com/dining_types/restaurants

    That being said, I still need to figure out how to get the structure site.com/dining/restaurants, aka site.com/custom-post-type/term-name (leaving out the custom taxonomy, and using just the CPT and term). Would setting the "slug" field on the custom taxonomy to "dining" work? I just noticed this (making an edit), but I'm unsure if having the slug of the custom taxonomy the same as the custom post type will have any conflicts.


    Buy me a beer? | Try DigitalOcean VPS Hosting

    April 5, 2015 at 3:37 pm #146760
    Porter
    Participant

    A quick update to this:

    I can get is_post_type_archive to work (site.com/dining), but for whatever reason, I can't seem to get the taxonomy to work (site.com/dining/restaurants). The page is an archive, but my conditional check isn't working. I used:

    if (is_tax('dining', 'restaurants')) {

    I've tried just doing dining, to see if ALL terms would display in such a way, but no luck. What conditional check do I need to get site.com/dining/restaurants to use a custom archive? Again, dining is the custom post type, restaurants is a "term" of the "dining_types (slug "dining") custom taxonomy.


    Buy me a beer? | Try DigitalOcean VPS Hosting

    April 5, 2015 at 5:16 pm #146765
    Porter
    Participant

    I wish I could edit a post later, rather than within the first 15 minutes of posting. Anyway:

    I changed the rewrite slug of my custom taxonomy to "dining_types" instead of dining, and my conditional works now. This means that my custom post of "dining" is somehow conflicting with the rewrite slug of "dining" for my custom taxonomy.

    Between with_front, hierarchical, and the rest of the information I've taken in, I'm completely swamped / stumped. I feel like this should be relatively easy to achieve, but I just can't get it. If anyone could lend me a hand in putting this multi-week nightmare to rest, I'd be extremely grateful.


    Buy me a beer? | Try DigitalOcean VPS Hosting

    April 6, 2015 at 1:13 am #146778
    Brad Dalton
    Participant

    Don't you want to change the slug for register_taxonomy not the URL?

    You can change it in.

    'rewrite'   => array( 'slug' => 'portfolio-type', 'with_front' => false ),
    

    And then re-save your Permalinks.

    You'll also need to use the WordPress Template Hierarchy to name your files correctly so they're loaded correctly.

    Or

    You can use template_include with the correct conditional tag to force an archive to use a specific custom template.

    I think your problem is with the incorrect naming of your files for each term.


    Tutorials for StudioPress Themes.

    April 6, 2015 at 10:32 am #146816
    Porter
    Participant

    I am changing the slug in the rewrite (which changes the url), and I am re-saving my permalinks each time. I am NOT creating any files for the templates, as I don't want them, I'm only using template_include to assign templates to these files. Here is my register taxonomy code:

    function anib_custom_taxonomies() {
    	// Add new "Types" taxonomy to Posts
    	register_taxonomy('dining_types', 'dining', array(
    		// Hierarchical taxonomy (like categories)
    		'hierarchical' => true,
    		// This array of options controls the labels displayed in the WordPress Admin UI
    		'labels' => array(
    			'name' => _x( 'Types', 'taxonomy general name' ),
    			'singular_name' => _x( 'Location', 'taxonomy singular name' ),
    			'search_items' =>  __( 'Search Types' ),
    			'all_items' => __( 'All Types' ),
    			'parent_item' => __( 'Parent Location' ),
    			'parent_item_colon' => __( 'Parent Location:' ),
    			'edit_item' => __( 'Edit Location' ),
    			'update_item' => __( 'Update Location' ),
    			'add_new_item' => __( 'Add New Location' ),
    			'new_item_name' => __( 'New Location Name' ),
    			'menu_name' => __( 'Types' ),
    		),
    		// Control the slugs used for this taxonomy
    		'rewrite' => array(
    			'slug' => 'dining', // This controls the base slug that will display before each term
    			'with_front' => false, // Don't display the category base before "/Types/"
    			'hierarchical' => false// This will allow URL's like "/Types/boston/cambridge/"
    		),
    	));
    }

    The issue is (from my testing), that when the rewrite slug is "dining" (what I want the url to be, site.com/dining/restaurants, restaurants being a term of dining_types), it breaks. I believe this is because the Custom Post Type the taxonomy belongs to is ALSO named dining, so the slug of dining is being used by both, and somehow conflicting. I changed the taxonomy slug to dining_types in the rewrite, and the conditional for template_include worked, but will NOT work when it's "dining". That being said, the slug rewrite is 100% useless to me if I can't get it to be "dining", as that's what I want the url to be.


    Buy me a beer? | Try DigitalOcean VPS Hosting

    April 6, 2015 at 10:49 am #146820
    Porter
    Participant

    It's worth noting that my permalink structure is still /%category%/%postname%, as I don't know what it needs to be changed to work with custom post types and taxonomies, if anything. I think I may need to add some code to my site-specific plugin using the rewrite API, but I'm not sure.


    Buy me a beer? | Try DigitalOcean VPS Hosting

    April 6, 2015 at 11:34 pm #146881
    Porter
    Participant

    After a lot of testing, I confirmed I had a permalink conflict.

    "A common issue that arises when you create your own permalinks are permalink conflicts. Permalink conflicts occur when two permalinks share the same regular expression structure."

    My custom post type slug of "dining" was conflicting with the rewrite slug of "dining" for the custom taxonomy. I thought I was safe in giving them unique names, but apparently the names mean very little, and it's the slug that causes issues (or perhaps both).

    What I've determined, is that I either need to disable the custom post type archive, or disable taxonomy archives (but not terms). This is because I want:

    site.com/dining (custom taxonomy archive OR custom post type archive, but NOT both)
    site.com/dining/cafes (term archive)

    Am on the right track? Any ideas how to go about that?


    Buy me a beer? | Try DigitalOcean VPS Hosting

    April 9, 2015 at 8:34 pm #147265
    Porter
    Participant

    I'm still desperately seeking help with this.

    Seeing as I can't have the same slug for the custom post type, and the custom taxonomy, I need a way to work around that to get my url structure. All I need is this:

    site.com/dining (works)
    site.com/dining/specific-location (404)
    site.com/dining/custom-term-a (works)
    site.com/dining/custom-term-b (works)

    I refuse to believe this isn't possible, it's so basic, and so logical. Let me add that I also don't need WordPress to do anything with these by default, I'm adding my own templates, so "messing up default behavior" isn't an issue, I just need those urls to work. There must be a rewrite rule, or something out there, that will allow this.


    Buy me a beer? | Try DigitalOcean VPS Hosting

    May 10, 2015 at 9:43 am #151495
    Porter
    Participant

    The answer can be found here - http://wordpress.stackexchange.com/questions/108642/permalinks-custom-post-type-custom-taxonomy-post


    Buy me a beer? | Try DigitalOcean VPS Hosting

  • Author
    Posts
Viewing 10 posts - 1 through 10 (of 10 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble