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

Have a Custom Post Type index page display taxonomy items instead of posts

If you’d like to list the individual courses, i.e. the taxonomy terms, you’d use neither WP_Query nor the WP standard Loop. Instead, make use of the get_terms function to retrieve the courses. It returns an array of term objects (if the taxonomy does exist and has terms matching the function arguments). Iterate over that and … Read more

get_term_children returns WP_Error for custom taxonomy

Since get_term_link() will return a WP_Error object if the term does not exist, you could try: $termchildren = get_term_children( $taxID, $taxType ); echo ‘<ul>’; foreach ( $termchildren as $child ) { $term = get_term_by( ‘id’, $child, $taxType ); $term_link = get_term_link( $term->name, $taxType ); if( ! is_wp_error( $term_link ) ) echo ‘<li><a href=”‘ . $term_link … Read more