Community Forums › Forums › Archived Forums › Design Tips and Tricks › CPT custom taxonomy problem
Tagged: CPT, Custom Post Type, custom taxonomy, taxonomy links
- This topic has 8 replies, 2 voices, and was last updated 7 years, 5 months ago by jaiji.
-
AuthorPosts
-
March 21, 2017 at 1:43 pm #203583jaijiParticipant
Hi
I have a CPT (artist) with 2 custom taxonomies (stage, day) and their respective templates. I have the taxonomies displayed in the entry-meta which I've hooked in below the post title. All good. Except, when I click the Stage link, it takes me to the archive for that category as intended, but when I click on the Day link, it takes me to the correct permalink (e.g. website-url/day/saturday) but it displays my blog page.
Here's the code for displaying the taxes, I think the problem must be here but I don't know enough to diagnose. Any tips much appreciated.
Also (alternatively): is it possible to display the text for each taxonomy without the link? I only really need the text.
Site's in dev at the moment so no link.
//* Display multiple custom taxonomy items in the post meta add_filter( 'genesis_post_meta', 'afn_display_custom_tax' ); function afn_display_custom_tax($post_meta) { if ( ! is_singular( 'artist' ) ) return; $post_meta = '[post_terms taxonomy="stage" before="Where: "] [post_terms taxonomy="day" before="When: "]'; return $post_meta; }
Taxonomy registration:
$labels = array( 'name' => 'Day', 'label' => 'Days', 'menu_name' => 'Day', 'all_items' => 'All Days', 'edit_item' => 'Edit Day', 'view_item' => 'View Day', 'update_item' => 'Update Day', 'add_new_item' => 'Add New Day', 'new_item_name' => 'New Day', ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'label' => 'Days', 'show_ui' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'day', 'with_front' => true ), 'show_admin_column' => false, ); register_taxonomy( 'day', array( 'artist' ), $args );
March 21, 2017 at 6:12 pm #203609jaijiParticipantAs far as I can tell it's to do with the templates. Strangely, Stages is using the assigned archive-artist.php and displaying as it should. Days is using index.php, even though it's been assigned the same archive-artist.php. Both CPTs are created in exactly the same way, as are the taxonomies (both in a simple plugin) and otherwise behave as expected. There are no other references to 'days' anywhere else.
I'm assigning the template with this from Sridhar:
add_filter( 'template_include', 'sk_template_redirect' ); function sk_template_redirect( $template ) { if ( is_tax( 'stage' ) || is_tax( 'day') ) $template = get_query_template( 'archive-artist' ); return $template; }
Is anything obviously wrong with this?
March 23, 2017 at 4:18 pm #203748Brad DaltonParticipantYou need to name the files correctly using the WordPress Template Hierarchy.
Example taxonomy-artist.php however this depends on how you coded the CPT
And remove the code for template_include.
March 23, 2017 at 4:51 pm #203751jaijiParticipantThanks Brad. I don't get how it works fine for one category but not the other though?
March 23, 2017 at 4:55 pm #203752Brad DaltonParticipantAre you using categories or custom taxonomy types for your CTP?
My solution is tested using custom taxonomy types.
March 23, 2017 at 5:22 pm #203755jaijiParticipantAlso the template redirect is working and the first taxonomy 'stage' is using the arist-archive.php just fine, it's just the second that isn't.
March 23, 2017 at 5:54 pm #203757jaijiParticipantSorry Brad, I missed your earlier reply. I'm using custom taxonomies. The template redirect works for one of them though, as intended, which is why I'm confused. Could a custom taxonomy template be the same (content-wise) as the main CPT archive template, just named and titled to suit?
March 23, 2017 at 6:41 pm #203759jaijiParticipantI've just uploaded two category archive templates and removed the template_include, and flushed permalinks. Same problem, 'stages' works and 'days' goes to the blog. I have flushed permalinks.
Especially frustrating as I don't actually want or need the archives, I just need their names displayed on the CPT in the entry meta but I don't know how to strip out the links.
March 24, 2017 at 11:23 am #203775jaijiParticipantFixed. The problem was using 'Day' as one of the terms, which I now know is a query var reserved for use by WordPress. I changed the term name, menu name, the arg label and the rewrite slug to 'when' instead, then re-added the relevant terms to the CPT and all is good. The template rewrite is working fine too.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.