Loop posts based on permalink term

Got it to work with: $queried_object = get_queried_object () ; and ‘terms’ => $queried_object->slug, full code now: <?php $queried_object = get_queried_object () ; $posts = array ( ‘post_type’ => ‘writing’, ‘posts_per_page’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘type’, ‘field’ => ‘slug’, ‘terms’ => $queried_object->slug, ), ), ); $loop = new WP_Query( $posts ); … Read more

Get posts in taxonomy randomly

You have syntax error in tax_query. ‘tax_query’ => array( array ( ‘taxonomy’ => $term->taxonomy, ‘field’ => ‘term_id’, // this is default value, so can be ommited ‘terms’ => $term->term_id, ) ) As you can read in Codex, possible values for field parameter are: term_id (default), name, slug or term_taxonomy_id. In this question you can read … Read more

Custom Category Walker with Image, Fallback to Most Recent Post in Category Image

The solution to the problem is that the tax_query needs to be an array of arrays. Thank you Sally CJ for the comment above, which also reminded me to $query->request. Here’s the total Walker for anyone for whom it’s useful: class List_Category_Walker extends Walker_Category { function start_el( &$output, $category, $depth = 0, $args = array(), … Read more

How to set `tax_query` with `query->set()`

Main problem with your code is that tax_query should be an array of queries, and not a single query. $tax_query = array( array( ‘taxonomy’ => ‘filter’, ‘terms’ => array(30140, 30020, 30008, 29998, 29991, 21458,20197,11986,6614), ‘field’ => ‘term_id’, ‘operator’ => ‘NOT IN’ ) ); $query->set( ‘tax_query’, $tax_query );

Set both meta_query and tax_query using wp_query->set

Just use another set() method: if ($value[‘pRange’] && $value[‘tags’]) { $wp_query->set(‘tax_query’, array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘product_tag’, ‘field’ => ‘slug’, ‘terms’ => $value[‘tags’], ), array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => $value[‘tags’], ), array( ‘taxonomy’ => ‘pa_branding’, ‘field’ => ‘slug’, ‘terms’ => $value[‘tags’], ), ) ); $wp_query->set(‘meta_query’, array( ‘relation’ => ‘AND’, … Read more