Community Forums › Forums › Archived Forums › General Discussion › How to display custom taxonomy terms
Tagged: custom taxonomies
- This topic has 2 replies, 2 voices, and was last updated 10 years, 3 months ago by Sridhar Katakam.
-
AuthorPosts
-
January 2, 2014 at 3:01 pm #82750shelley423Member
I have added a custom taxonomy called "stores". Each post will have a category, store, and tags. This is NOT on a custom post type. My problem is I can't figure out to make the link to the terms under the store to display in the theme.
So for example, a post about a toy sale on Amazon might be in the category "Online Deals", listed under the store "Amazon" and tagged "toys".
On the bottom of the post, in the post meta, I want it to display categories and store and I can't get it to display the store. This is what I entered in functions.php and only categories show up.
//* Customize the post meta function add_filter( 'genesis_post_meta', 'sp_post_meta_filter' ); function sp_post_meta_filter($post_meta) { if ( !is_page() ) { $post_meta = the_terms( $post->ID, 'category', 'Categories: ', ' , ' ); the_terms( $post->ID, 'stores', 'Store: ', ', ', ' ' ); return $post_meta; }}
This is what I did to add the taxonomy "stores":
// hook into the init action and call create_taxonomies when it fires add_action( 'init', 'sh_create_taxonomies', 0 ); // create new taxonomies for the post type "post" function sh_create_taxonomies() { // Add new taxonomy, make it hierarchical (like categories) $labels = array( 'name' => _x( 'Stores', 'stores' ), 'singular_name' => _x( 'Store', 'stores' ), 'search_items' => _x( 'Search Stores', 'stores' ), 'popular_items' => _x( 'Popular Stores', 'stores' ), 'all_items' => _x( 'All Stores', 'stores' ), 'parent_item' => _x( 'Parent Store', 'stores' ), 'parent_item_colon' => _x( 'Parent Store:', 'stores' ), 'edit_item' => _x( 'Edit Store', 'stores' ), 'update_item' => _x( 'Update Store', 'stores' ), 'add_new_item' => _x( 'Add New Store', 'stores' ), 'new_item_name' => _x( 'New Store', 'stores' ), 'separate_items_with_commas' => _x( 'Separate stores with commas', 'stores' ), 'add_or_remove_items' => _x( 'Add or remove stores', 'stores' ), 'choose_from_most_used' => _x( 'Choose from the most used stores', 'stores' ), 'menu_name' => _x( 'Stores', 'stores' ), ); $args = array( 'labels' => $labels, 'public' => true, 'show_in_nav_menus' => true, 'show_ui' => true, 'show_tagcloud' => true, 'show_admin_column' => true, 'hierarchical' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'stores', 'with_front' => false, // Don't display the category base before "/Stores/" 'hierarchical' => true ), ); register_taxonomy( 'store', array('post'), $args ); }
It also seems that the store doesn't show up under the admin column, which may or may not be related?
I am using the Adorable theme.
I would appreciate any insight anyone could give me. Thanks.
http://cnyscouponing.staging.wpengine.com/test-post-amazon-deal-toys/January 4, 2014 at 7:10 am #83100Sridhar KatakamParticipantUse this instead:
add_filter( 'genesis_post_meta', 'sp_post_meta_filter' ); function sp_post_meta_filter($post_meta) { if ( !is_page() ) { $post_meta = '[post_categories before="Categories: "] [post_terms taxonomy="store" before="Store: "]'; return $post_meta; } }
Source: http://my.studiopress.com/docs/shortcode-reference/
January 4, 2014 at 7:13 am #83101Sridhar KatakamParticipantand just for kicks, if we were to do something similar using actions instead of a filter..
//* Remove post meta from single Posts // add_action ( 'genesis_entry_content', 'sk_remove_post_meta' ); function sk_remove_post_meta() { if ( !is_singular('post' ) ) return; remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); } //* Add custom post meta on single Posts // add_action( 'genesis_entry_footer', 'sk_post_meta' ); function sk_post_meta() { if ( !is_singular('post' ) ) return; echo '<p class="entry-meta">'; echo do_shortcode('[post_categories]'); echo do_shortcode('[post_tags]'); echo the_terms( $post->ID, 'store', '<span class="entry-stores">Store: ', ' , ', '</span>' ); echo '</p>'; }
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.