tax_query (if the terms are empty)

I would start by reorganizing your $args code to make more sense. $now = date(‘d-m-Y H:i:s’); $cat=”featured”; $args = $cat_args = array( ‘post_type’ => ‘events’, ‘posts_per_page’ => 4, ‘meta_key’ => ‘start_date’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘start_date’, ‘value’ => date(‘Ymd’, strtotime(‘now’)), ‘type’ => ‘numeric’, ‘compare’ … Read more

How to search for meta_query LIKE or tax_query LIKE and grab these posts on search results?

Looking at WP_Tax_Query and WP_Meta_Query used by Wp_Query, they return their respective where clauses with an AND relation, and no hook or $args to change that behavior. Furthermore, the tax_query is computed before the rest of the main query so that it’s included in the main query in term_taxonomy_id IN (…) form. Also the WP_Tax_Query … Read more

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 );

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)