How to limit posts to 1 from each term with tax_query?

<?php $categories = array(‘economy’,’the-constitution’,’monetary-policy’,’liberty’); foreach($categories as $category) { $args = array( ‘posts_per_page’ => 1, ‘category_name’ => $category, ‘tax_query’ => array( array( ‘taxonomy’ => ‘highlight’, ‘field’ => ‘slug’, ‘terms’ => array( ‘lead’,’featured’ ), ‘operator’ => ‘NOT IN’ ) ) ); $wpse42358_query = new WP_Query( $args ); while( $wpse42358_query->have_posts() ) : $wpse42358_query->the_post(); // write post stuff here … Read more

Custom Query Arguments

/** * Define a new function that uses $args and wp_parse_args() */ function explain_parse_args( $args ) { $defaults = array ( ‘text’ => ‘wp_parse_args() merges $args into $defaults’, ‘before’ => “”, ‘after’ => ” \n”, ‘echo’ => TRUE ); // Parse incomming $args into an array and merge it with $defaults $args = wp_parse_args( $args, … Read more

How to update WordPress custom SQL Select query for custom taxonomies so that syntax is correct?

You should not use a direct SQL query, instead try the WP_Query tax queries e.g.: $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘id’, ‘terms’ => array( 22 ) ), array( ‘taxonomy’ => ‘job’, ‘field’ => ‘name’, ‘terms’ => $terms, ‘operator’ => ‘IN’ ) ) … Read more

Advanced AND tax_query in sidebar with 2 taxonomies

You are using get_the_term_list which generates an HTML string of taxonomy terms associated with a post and given taxonomy. Try instead to feed the terms input parameters of the WP_Query with an array like: ‘terms’ => array( 11, 22, 33 ), or ‘terms’ => array( ‘term1’, ‘term2’, ‘term3’ ), In your code example you have … Read more

Match two taxonomies to display a specific content

You’ll want to have a look at get_the_terms(). <?php // You need to define the post id from the post you are outputting in the right bar so that the left bar knows how to match up the terms $country = get_the_terms( $post->id, ‘countries’ ) $args = array( ‘post_type’ => ‘side_menu’, ‘posts_per_page’=> 1, ‘tax_query’ => … Read more