Sort post’s categories by ID

You’re using wrong arguments for get_the_category_list function. The function you should use for this is wp_get_object_terms http://codex.wordpress.org/Function_Reference/wp_get_object_terms

Exclude category from loop not working

Don’t use query_posts(). Use pre_get_posts instead: function wpse82745_filter_pre_get_posts( $query ) { // Only modify the main loop, // and only in the blog posts index if ( is_home() && $query->is_main_query() ) { $query->set( ‘category__not_in’, array( ’13’ ) ); } } add_action( ‘pre_get_post’, ‘wpse82745_filter_pre_get_posts’ ); This callback will exclude category 13 from the main loop in … Read more

Woocommerce – Get product category 2nd level category

Assuming you know the parent category ID, you can use get_terms() function. $args = array( ‘parent’ => 100 // id of the direct parent ); $cats = get_terms( ‘product_cat’, $args ); foreach( $cats as $cat ) { echo $cat->name; } Here is more information on this function and additional arguments you can use. http://codex.wordpress.org/Function_Reference/get_terms

When to use ‘get_category_by_path’ vs. ‘get_term_by’ to get category object from `get_query_var( ‘category_name’ )`?

You’re doing it correct @its_me. The latter, get_term_by() would be the best way, In my opinion , as I believe get_category_by_path uses get_term_by, just prepopulating the taxonomy to be category. Edit: As I mentioned in my comment, get_category_by_path is much less efficient, since it gets multiple terms,. and then compares the hierarchical path. get_term_by is … Read more

Apply custom category template to subcategories

If a is the category slug, then following code would work – add_action(‘template_include’, ‘wpse129481_template_include’); function wpse129481_template_include($t) { // is category archive page if( is_category() ) { // current queried category id from queried object $child_id = get_queried_object_id(); // parent category object, getting it by slug. $parent_cat = get_term_by(‘slug’, ‘a’, ‘category’); // current category object, can … Read more