Is there a way to ‘Lock’ a Taxonomy?

Categories, Tags & Taxonomies First i want to make this one clear: Everything is a Taxonomy. Tags is a non-hierarchical, Categories a hierarchical and both are built-in taxonomies. Same goes for eg. post formats (aside, chat, etc.). It’s the same concept as with post-types (post, page, attachment, nav_menu_item, etc. are all just built in post … Read more

Get Terms by IDs with IDs order

So I believe the question is how to get the terms back in the order of the Ids you’ve provided – which might not be sorted ascending or descending, but a random order instead. Surprisingly, I think there’s a shortcut for that in WP – who knew? This, I believe, is what you want to … Read more

Automatically Assign Parent Terms When A Child Term is Selected

Hooking into save_post action. add_action(‘save_post’, ‘assign_parent_terms’, 10, 2); function assign_parent_terms($post_id, $post){ if($post->post_type != ‘product’) return $post_id; // get all assigned terms $terms = wp_get_post_terms($post_id, ‘product_cat’ ); foreach($terms as $term){ while($term->parent != 0 && !has_term( $term->parent, ‘product_cat’, $post )){ // move upward until we get to 0 level terms wp_set_post_terms($post_id, array($term->parent), ‘product_cat’, true); $term = get_term($term->parent, … Read more

Woocommerce get category image full size

Thanks to Mike Jolley (Woocommerce plugin author) for the solution using: wp_get_attachment_image_src $prod_categories = get_terms( ‘product_cat’, array( ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘hide_empty’ => true )); foreach( $prod_categories as $prod_cat ) : $cat_thumb_id = get_woocommerce_term_meta( $prod_cat->term_id, ‘thumbnail_id’, true ); $shop_catalog_img = wp_get_attachment_image_src( $cat_thumb_id, ‘shop_catalog’ ); $term_link = get_term_link( $prod_cat, ‘product_cat’ );?> <a href=”https://wordpress.stackexchange.com/questions/200170/<?php echo … Read more

Query users by custom taxonomy and user role

Apparently there is no core implementation of ‘tax_query’ in WP_User_Query yet. Check the ticket here for more info –> https://core.trac.wordpress.org/ticket/31383 Nevertheless there is an alternative way using get_objects_in_term $taxonomy = ‘shop-category’; $users = get_objects_in_term( $term_id, $taxonomy ); if(!empty($users)){ // WP_User_Query arguments $args = array ( ‘role’ => ‘shop_manager’, ‘order’ => ‘DESC’, ‘orderby’ => ‘user_registered’, ‘include’ … Read more

get_terms vs. get_categories: does it matter?

As you dive into WordPress, you’ll find that WordPress has a lot of wrapper functions. For instance, there’s add_theme_page that’s just a wrapper of add_submenu_page. That’s certainly not the only example (add_submenu_page itself has a bunch of wrappers, in fact). If you look at the source for get_categories(), you’ll see that it too is a … Read more