WP Query filtering by custom category not showing all relevant posts

@jacob-peattie answered the question in his comment – I used the wrong key to set the number of posts my query generates. Swapping numberposts with posts_per_page solved the issue. Here’s the final query: @php $cats = get_sub_field(‘reviews_category’); // gets the custom field categories $args = array( ‘post_type’ => ‘testimonials’, ‘posts_per_page’ => -1, // this line … Read more

Passing a variable containing a comma separated list of values in a meta-query

In WordPress meta queries, when using the ‘compare’ => ‘IN’ comparison, the value should be an array, not a string. When you manually input array( ‘1302’, ‘1329’ ), it works because it’s correctly formatted as an array. However, when using $artists_string_value, it’s treated as a single string, not an array of values. You should modify … Read more

WP_Query not using relation key as expected and not producing any results

From the developer docs: relation (string) – The logical relationship between each inner meta_query array when there is more than one. Possible values are ‘AND’, ‘OR’. Do not use with a single inner meta_query array. (Emphasis mine). It’s a bit hacky, but you could run a separate query against the meta field, then merge the … Read more

Meta query array – same order as specified order in value

Use PHP to sort the results after the query (untested): $product_ids = array( 3624, 1298, 430, 5629, 765 ); $query = new WP_Query( array( ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘product_id’, ‘value’ => $product_ids, ‘compare’ => ‘IN’, ), ), ) ); $posts_by_product_id = array(); $sorted_posts = array(); if ( $query->have_posts() ) { … Read more

WordPress – Optimize the Meta Query for 3 meta keys at a time

Conclusion – In my case I tried below When I changed placement of last meta or at the first place worked perfectly. <?php $price_from = ’20’; $price_to = ‘700’; $meta_query_price[] = array( ‘relation’ => ‘OR’, array( ‘key’ => ‘price_type’, ‘value’ => ‘POA’, ‘type’ => ‘value’, ‘compare’ => ‘LIKE’ ), array( ‘relation’ => ‘AND’, array( ‘key’ … Read more

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