How do I get a list of all categories that a given user has written blog posts for?

As, much as I know about WordPress we have to ways to achieve this. First: You have to retrieve all posts written by an author an then you can fetch categories assigned to those posts. Store them in an array uniquely. $args = array(‘author’ => $author->ID, ‘posts_per_page’ => -1, ‘fields’ => ‘ids’); $authorArticles = get_posts($args); … Read more

Get child product categories from parent product category in WooCommerce

Edited (1) You will need to use ‘child_of’ from WP_Term_Query available arguments, that will let you to get all child terms for the current product category parent term: // Only on product category archive pages if( is_product_category() ) { $main_term = get_queried_object(); $args_query = array( ‘taxonomy’ => ‘product_cat’, ‘hide_empty’ => false, ‘child_of’ => $main_term->parent ); … Read more

get_the_terms – only top level

Just have a quick test and seems both methods working well. // @Rup’s method $terms = get_the_terms(get_the_ID(), ‘my_taxonomy’); if (!is_wp_error($terms) && !empty($terms)) { foreach ($terms as $term) { // skip if parent > 0 if( $term->parent ) continue; $name = $term->name; $link = add_query_arg(‘fwp_typ’, FWP()->helper->safe_value($term->slug), ‘https://www.freuciv.com/’); echo “<a href=”https://wordpress.stackexchange.com/questions/366690/$link”>$name</a><br />”; } } or $terms = … Read more

Formulate a url to show posts with both taxonomy terms

Looks like you can define the AND logical operator with the URL parameters, specifically adding the “+” between your terms like this: url?taxonomy=term1+term2 This will ensure that only posts containing all terms listed are returned. Example: https://example.com/blog?food=sauce+cheese [tax_query] => WP_Tax_Query Object ( [queries] => Array ( [0] => Array ( [taxonomy] => food [terms] => … Read more

Get list of terms that have posts in another term

Try replacing ‘operator’ => ‘AND’ with ‘relation’=>’AND’ Updated Code Snippet: $current_color = get_queried_object_id(); $query = new WP_Query( array( ‘post_type’ => ‘product’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ‘tax_query’ => array( ‘relation’ => ‘AND’ array( ‘taxonomy’ => ‘pa_color’, ‘field’ => ‘term_id’, ‘terms’ => $current_color, ), array( ‘taxonomy’ => ‘product_cat’, ‘field’ … Read more

List Terms in Category

Since you are in a category the your query will get the posts of that category, you only need to add ‘posts_per_page’ => -1 to that query so it will get you all the posts in that category and not the default “at most” number. so something like: query_posts( $query_string . ‘&posts_per_page=-1’ ); this will … Read more

How to list 2 taxonomy terms for a post, based on their hierarchy

I managed to hack this together using wp_get_object_terms. The ‘orderby’ => ‘term_id’ was most helpful. It’s probably not the best method, but seems to work fine. Because the child terms (suburbs) are always created after the parent terms (Cities), they will always have a higher ID. <?php $terms = wp_get_object_terms($post->ID, ‘location’, array(‘orderby’ => ‘term_id’, ‘order’ … Read more

Check if term is in a taxonomy?

You’re probably looking for term_exists(): <?php term_exists( $term, $taxonomy, $parent ); ?> $term is required (obviously). Both $taxonomy and $parent are optional, but if you want to determine if a specific taxonomy has a given term, just pass the registered taxonomy name via the $taxonomy parameter.

Adding action to save_post, post needs to be saved twice for function to work

This is a stab in the dark, but have you tried using the set_object_terms hook for your bam_save_event_cat function? function bam_save_event_cat( $post_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ) { $taxonomy = ‘categoria’; $tribe_cats = get_the_terms( $post_id, ‘tribe_events_cat’); foreach($tribe_cats as $tribe_cat) { if( empty($tribe_cat->name) ) continue; $catname = $tribe_cat->name; $cats[] = $catname; } wp_set_object_terms( $post_id, $cats, … Read more