How to combine two WP_Query objects?

What about just querying for both terms and increasing the posts_per_page count. $category_query = new WP_Query([ ‘posts_per_page’ => 36, ‘post_type’ => ‘product’, ‘tax_query’ => [ [ ‘taxonomy’ => ‘product_cat’, ‘terms’ => [ 120, 121 ], ‘field’ => ‘id’, ‘include_children’ => false ] ] ]); EDIT: Running a query with more that one term and guarantees … Read more

Yoast primary category query modification

I’m not sure this will fix it, but maybe try using the current category slug for the $current_category variable, instead of single_cat_title(), like so: $term = get_queried_object(); $current_category = $term->slug; This might help because the category_name parameter in WP_Query, despite its name, should be the term slug. single_cat_title() returns the displayed category title, not slug.

How to avoid bypass of search bar rules?

You want to use the pre_get_posts action to modify the search query on the server side. The pre_get_posts Codex have some examples to get you started. To target the main search query, try this: function my_search_filter( $query ) { if ( ! is_admin() && $query->is_main_query() ) { if ( $query->is_search ) { // Use $query->set(); … Read more

WP ForLoop to compare meta information of posts to determine what post to display

Your query should be something like this: $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 1, ‘meta_key’ => ‘<ACF FIELD KEY HERE>’, ‘meta_value’ => date( “Ymd” ), ‘meta_compare’ => ‘>’, ‘meta_query’ => array( ‘key’ => ‘<ACF FIELD KEY HERE>’, ‘value’ => date( “Ymd” ), ‘compare’ => ‘>’ ), ‘orderby’ => ‘meta_value_datetime’, ‘order’ => ‘ASC’, ); … Read more

Exclude a Woocommerce product from WP_Query

You can use “post__not_in” Parameter. add your products id in array which you want to exclude. $default = array( ‘post_type’ => ‘product’, ‘post__not_in’ => array(2024), ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘post_status’ => ‘publish’, ‘showposts’ => $numberposts ); if( $category != ” ){ $term = get_term_by( ‘slug’, $category, ‘product_cat’ ); if( $term ) : $term_name … Read more

WP_Query Taxonomy categories filtering

You can nest your tax queries. Just make sure you use OR as the first relation and AND relation on the nested tax queries. $filter_group_a = array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => $term_a, ), array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => $term_b, ), ); $filter_group_b = … Read more