Custom Permalinks for Custom Post Types and Taxonomies

Here’s the method I use to get what you’re trying to achieve. First, register your location taxonomy: register_taxonomy( ‘location’, array( ‘business’ ), array( ‘rewrite’ => array( ‘slug’ => ‘business-location’ ) ) ); Next, register the business post type. The important bit to note here is the inclusion of the %location% rewrite tag in the slug. … Read more

Get current term’s ID

Here is a function I use to list subterms: /** * Lists all subentries of a taxonomy. * * @return void */ function ttt_get_subterms( $args = array () ) { if ( ! isset ( get_queried_object()->taxonomy ) ) { return; } $options = array ( ‘child_of’ => get_queried_object_id() , ‘echo’ => 0 , ‘taxonomy’ => … Read more

Custom-Taxonomy as categories: Remove “most-used” tab?

Yes – you need to first ‘de-register’ the metabox WordPress automatically creates: add_action( ‘admin_menu’, ‘myprefix_remove_meta_box’); function myprefix_remove_meta_box(){ remove_meta_box(‘my-tax-metabox-id’, ‘post’, ‘normal’); } Where my-tax-metabox-id is the ID of your metabox. Then ‘re-register’ the metabox providing your own callback function which produces in the output: //Add new taxonomy meta box add_action( ‘add_meta_boxes’, ‘myprefix_add_meta_box’); function myprefix_add_meta_box() { add_meta_box( … Read more

Get main parent categories for a product

just to offer a alternative solution that might help somebody: code function wc_origin_trail_ancestor( $link = false, $trail = false ) { if (is_product_category()) { global $wp_query; $q_obj = $wp_query->get_queried_object(); $cat_id = $q_obj->term_id; $descendant = get_term_by(“id”, $cat_id, “product_cat”); $descendant_id = $descendant->term_id; $ancestors = get_ancestors($cat_id, ‘product_cat’); $ancestors = array_reverse($ancestors); $origin_ancestor = get_term_by(“id”, $ancestors[0], “product_cat”); $origin_ancestor_id = $origin_ancestor->term_id; … Read more

custom post type taxonomies UI radiobuttons not checkboxes

When you register a taxonomy WordPress automatically handles producing the appropriate metabox. First you need to ‘de-register’ this default metabox: add_action( ‘admin_menu’, ‘myprefix_remove_meta_box’); function myprefix_remove_meta_box(){ remove_meta_box(‘my-tax-metabox-id’, ‘post’, ‘normal’); } Where my-tax-metabox-id is the ID of your metabox. Then ‘re-register’ the metabox providing your own callback function which produces in the output: //Add new taxonomy meta … Read more

How to check if last uri segment is a custom post type or taxonomy term?

To see how we can make this work, have a read through the Query Overview Codex page, particularly the What Plugins can Modify section: Modify the query specification, after variable values are saved (request filter or parse_request action; if you want to use conditional tag tests, use the parse_query or pre_get_posts action, as these run … Read more