Get taxonomy name of current post
get_ancestors() should do what you need: So, you should do something like this: $ancestors = get_ancestors($term_id, ‘projects_category)
get_ancestors() should do what you need: So, you should do something like this: $ancestors = get_ancestors($term_id, ‘projects_category)
Firstly, $product->get_categories() won’t work because it’s a woocommerce function, that basically is just a wrapper for get_the_term_list, which has no sorting parameter. It’s always good to take a look at the source to know what you’re dealing with. Secondly,get_the_term_list uses get_the_terms, but it also has no sorting parameter. The latter get the terms either from … Read more
If you want to retrieve multiple taxonomies you need to put the four taxonomies in an array, you are doing this, but you have put taxonomy=> in the array. $terms = get_terms( ‘taxonomy’ => array( ‘vehicle_safely_features’, ‘vehicle_exterior_features’, ‘vehicle_interior_features’, ‘vehicle_extras’) ); Hope it helps
Just to start, you say “I am using get_terms to retrieve all terms from Tax 1 with posts associated with it”, however your actual code gets all terms in that taxonomy regardless of whether or not they have posts. You need to set hide_empty to true. So with that out of the way, the bad … Read more
When you’re doing a tax_query or meta_query in a WP_Query, you always have to use a nested array( array() ); just see the following example for an explanation and pay attention to the relation argument. $packages = new WP_Query( array( ‘post_type’ => ‘vamos-cpt-packages’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘vamos-holiday-types’, ‘field’ => … Read more
You use the hide_empty argument for $terms, but not for $this_term inside your loop. Also, with the way you’re generating your select, it would be a lot more efficient to just query top-level terms for the main loop: $terms = get_terms( ‘device’, array( ‘hide_empty’ => false, ‘parent’ => 0 ) ); And then drop if($term->parent … Read more
Put list in PHP array, loop through it, use wp_insert_term() on each.
Hereby my answer to my own post. I hope this is helpful to others too! To create the category, I used an array with the data per category needed for the function wp_insert_term. Then i looped trough that array,and used a fetch_media function that uploads the image found in the image-path given to that function, … Read more
Thank you guys for such quick response. Much appreciated! Here is code for “global” Tags page (displaying terms of default ‘post_tag’ taxonomy): <?php $term_slug = get_queried_object()->slug; if ( !$term_slug ) return; else $loop = new WP_Query( array( ‘post_type’ => ‘any’, ‘tag’ => $term_slug, ‘posts_per_page’ => 10 ) ); while ( $loop->have_posts() ) : $loop->the_post(); ?> … Read more
Public API for the rescue category is a Taxonomy that’s already built in. Therefore it’s quite easy to get its term count with get_terms( $tax, array( /* args */ ) ); $terms = get_terms( ‘category’, array( ‘fields’ => ‘count’, ) ); This will do a pretty fast COUNT (*) query so you don’t have to … Read more