Title: meta_query problem
Last modified: June 4, 2023

---

# meta_query problem

 *  [wp_user1](https://wordpress.org/support/users/wp_user1/)
 * (@wp_user1)
 * [2 years, 12 months ago](https://wordpress.org/support/topic/meta_query-problem-2/)
 * Hey, first of all – thanks for the great plugin.
 * I use custom layouts with filter for meta-fields. That works fine this way:
 *     ```wp-block-code
       function layout_query_args( $query_args, $id ) {
       $query_args['meta_key'] = 'fieldname';
       $query_args['meta_value'] = 'value1';
       $query_args['meta_compare'] = 'LIKE';
       return $query_args;
       }
       ```
   
 * But how can I filter to have fieldname=value1 OR fieldname=value2? I tried it
   his way but then I get no results:
 *     ```wp-block-code
       $query_args = array(
       	'meta_query' => array(
       		array(
       			'key' => 'fieldname',
       			'value' => array( 'value1', 'value2' ),
       			'compare' => 'in',
       		)
       	)
       );
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [wp_user1](https://wordpress.org/support/users/wp_user1/)
 * (@wp_user1)
 * [2 years, 12 months ago](https://wordpress.org/support/topic/meta_query-problem-2/#post-16793000)
 * I tried it this way, but then **all** entries are shown..
 *     ```wp-block-code
       $query_args ['meta_query'] =
       array(
       'key' => 'fieldname',
       'value' => array( 'value1', 'value2'),
       'compare' => 'IN',
       )
       ;
       ```
   
 *  Thread Starter [wp_user1](https://wordpress.org/support/users/wp_user1/)
 * (@wp_user1)
 * [2 years, 12 months ago](https://wordpress.org/support/topic/meta_query-problem-2/#post-16793786)
 * Debug of working query:
 *     ```wp-block-code
       Array ( [fields] => ids [post_type] => Array ( [0] => projekt ) [post_status] => Array ( [0] => publish ) [posts_per_page] => 3 [paged] => 1 [orderby] => date [order] => desc [ignore_sticky_posts] => [post__not_in] => Array ( [0] => 602 ) [tax_query] => Array ( [relation] => AND ) [meta_key] => fieldname [meta_value] => value1 [meta_compare] => LIKE )
       ```
   
 * Debug of non-working query:
 *     ```wp-block-code
       Array ( [fields] => ids [post_type] => Array ( [0] => projekt ) [post_status] => Array ( [0] => publish ) [posts_per_page] => 3 [paged] => 1 [orderby] => date [order] => desc [ignore_sticky_posts] => [post__not_in] => Array ( [0] => 602 ) [tax_query] => Array ( [relation] => AND ) [meta_query] => Array ( [key] => fieldname [value] => Array ( [0] => value1 ) [compare] => IN ) )
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘meta_query problem’ is closed to new replies.

 * ![](https://ps.w.org/custom-layouts/assets/icon-256x256.png?rev=2475457)
 * [Custom Layouts - Post + Product grids made easy](https://wordpress.org/plugins/custom-layouts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/custom-layouts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/custom-layouts/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-layouts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-layouts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-layouts/reviews/)

 * 2 replies
 * 1 participant
 * Last reply from: [wp_user1](https://wordpress.org/support/users/wp_user1/)
 * Last activity: [2 years, 12 months ago](https://wordpress.org/support/topic/meta_query-problem-2/#post-16793786)
 * Status: not resolved