Tag Info

Hot answers tagged

2

What about using: echo get_the_term_list( $post->ID, 'artist-genre', '<li>', ',</li><li>', '</li>' ); instead, to generate the HTML list? Or simply: the_terms( $post->ID, 'artist-genre', '<li>', ',</li><li>', '</li>' ); that's a wrapper for get_the_term_list(). Also notice that you're missing the ...


1

If you are just after the term name in your code, you can add array( 'fields' => 'names' ) Or for PHP 5.4+ ['fields' => 'names'] as the third parameter to wp_get_post_terms. This will just retrieve the names of the terms attached to the post. You can then get and display the first post term name with echo $terms[0]]; As @birgire already ...


1

As you have already pointed out in your question, custom taxonomies are the way to go here. For this taxonomy to behave like the build in taxonomy post_tag, you need to set the hierarchical parameter to false. To make these taxonomy available to only your two specific post types, you need to specifiy this when registering your taxonomy. Example ...


1

Create a new template named e.g. taxonomy-course_topic.php In my example course_topic is the name of the custom taxonomy you registered. First parameter of register_taxonomy() function. See: register_taxonomy Taxonomy template


1

Thanks to Rarst for the tip. Here is the code I came up with to accomplish redirects for two similar taxonomy/post type set ups. This basically does what I indicated in the OP. If I hit a single post with a top-level term assigned to it, the url will go from domain/series/post/ to domain/series/ It simply strips the post's slug from the end of the url. ...


1

I would suggest querying a list of all post types using get_post_types. With that array you can do a foreach. and for each post type, query all terms with get_term. It would look something like this, but you should pass get_post_types your know post types, because as it stands, this will also display things like attachments and nav menus. function ...


1

get_the_term_list() returns HTML but you are trying to use it as if it returned a term ID -- 'blog_cats' => $blogcats,. That is not going to work. You will need to use get_the_terms() and a tax_query (I think. I am not 100% sure). Something like: $blogcats = get_the_terms($post->ID,'category'); // var_dump($blogcats); $blogcats = ...



Only top voted, non community-wiki answers of a minimum length are eligible