Nested tax_query that allows specified categories OR tags, but NOT other categories

I think I figured it out. This query appears to work: $args = array(); if ( isset( $term_ids ) && isset( $category_ids ) ) { $args[‘tax_query’] = array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘term_id’, ‘terms’ => $omit_category_ids, ‘operator’ => ‘NOT IN’, ), array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘category’, ‘field’ … Read more

Meta Query Array Error 500

In my previous answer (that I’ve deleted..), I suggested using custom SQL queries, which worked for me. However, since it didn’t work (well) for you, let’s try using this function: function get_player_stats( $player_id ) { $apps = 0; // Total appearances. $subs = 0; // Total sub-appearances. $goals = 0; // Total goals. // Get … Read more

Get amount of CPT with a certain custom field value

Well, it returns wrong number, because you’ve coded it exactly in that way 😉 Your WP_Query is correct. So when there are no posts matching your conditions, then you get 0. But when there are such posts, then… you ignore the query completely and return wp_count_posts as result… But… This function returns an object, whose … Read more

Assigning a meta_query value based on regexp to wp_query fails

Meta query should be an array of arrays (every array contains one condition). So instead of $meta_query = array( ‘key’ => ‘offer’, ‘value’ => $off, ‘compare’ => ‘=’ ); $query->set( ‘meta_query’, $meta_query ); There should be $meta_query = array( array( ‘key’ => ‘offer’, ‘value’ => $off, ‘compare’ => ‘=’ ) ); $query->set( ‘meta_query’, $meta_query ); … Read more

Set Transient does nothing

And that exactly how it will work, because that’s what you coded 😉 You set the transient correctly, but… You put only query arguments in there. And that doesn’t make much sense – it’s just an PHP array that is very easy and quick to create. And the query itself is executed always – it’s … Read more

need to exclude APP_TAX_STORE => $term->slug

The easiest way I can see is to gather a list of the terms in that taxonomy, and use them with a NOT IN operator in your query’s tax_query: // Get all the terms in your custom taxonomy. $slugs = get_terms( [ ‘taxonomy’ => ‘industry’, ‘fields’ => ‘slugs’, ] ); $posts = query_posts( [ ‘post_type’ … Read more

Create A Loop With A Variable Number of Posts For Each Bootstrap Row?

The easy-but-a-bit-hacky way to get there would be to initialize a counter variable before your loop and then use that to tell what post you’re on. something like so: $paged = (get_query_var(‘paged’)) ? absint(get_query_var(‘paged’)) : 1; $args = array( ‘post_type’ => ‘workshop’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => 11, ‘paged’ => $paged, ); $customQuery = new … Read more

How to combine two or more WP_Query?

Hope this code may work for you. $query1 = new WP_Query( array( ‘post_type’ => ‘product’, ‘s’ => $searchStr )); $query2 = new WP_Query( array( ‘post_type’ => ‘product’, ‘meta_query’ => array( array( ‘key’ => ‘my_meta_key’, ‘value’ => $searchStr, ‘compare’ => ‘LIKE’ ) ) )); $result = new WP_Query(); $result->posts = array_unique( array_merge( $query1->posts, $query2->posts ), SORT_REGULAR … Read more