WP_Query to output chosen term and posts with no term assigned

It’s actually pretty simple: You’ll want to use an OR relation, and use the NOT EXISTS operator for selecting posts that are not assigned to any terms in the specified taxonomy. $tax_query[] = array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘location’, ‘field’ => ‘name’, ‘terms’ => $location, ), array( ‘taxonomy’ => ‘location’, ‘operator’ => ‘NOT … Read more

How to display all posts not in a post_format

It didn’t work because your tax query is missing the operator which should be set to NOT IN. So just add it like so: ‘tax_query’ => array( array( ‘taxonomy’ => ‘post_format’, ‘field’ => ‘slug’, ‘terms’ => array( ‘post-format-‘ . $post_format ), ‘operator’ => ‘NOT IN’, ) ), And please, avoid using query_posts() — use new … Read more

Different options per post type in WP_Query

You could use pre_get_posts to conditionally add the tax_query depending on post-type, here’s a simple example. <?php function wpse_377928( $the_query ){ $post_type = $the_query->get(‘post_type’); if ( ‘type_a’ === $post_type ) { $tax_query = [ [ ‘taxonomy’ => ‘tax-1’, ‘field’ => ‘term_id’, ‘terms’ => array(11, 12, 13), ] ]; } elseif ( ‘type_b’ === $post_type ) … Read more

Order is breaking wp_query

The root cause to my issue was using the custom post type of “order”. Once I changed that to something more specific things worked fine. A complete guess but I’m wondering if the post type being “order” and the issue being the “order” query argument caused a conflict.

Get Child Category only

So if I understand correctly, the problem here is that get_the_terms(..) returns both the parent and child category. As you said in the comment, there will only ever be 1 parent and 1 child in it, we can use that information to get the correct term. Basically we need to filter the results, we know … Read more

Query_vars support in Rest API

correct me, if i’m wrong, but query vars are not processed in REST requests. but there is other ways to make this work. not really sure, if this will help with your problem but hopefully it is at least a push in the right direction function so380236_rest_cpt_query($args, $request) { $query_params = $request->get_query_params(); if (!array_key_exists(‘city’, $query_params)) … Read more

How to override url params with rewrite rules vars?

“hi” message is displayed instead of “hello” in the second example Yes, because that’s how it works: query_vars is a hook for registering custom query vars that are public, so if the URL query string contains the custom query var, then WordPress will set the query var to the value parsed from the query string. … Read more