• Hey, first of all – thanks for the great plugin.

    I use custom layouts with filter for meta-fields. That works fine this way:

    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:

    $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

    (@wp_user1)

    I tried it this way, but then all entries are shown..

    $query_args ['meta_query'] =
    array(
    'key' => 'fieldname',
    'value' => array( 'value1', 'value2'),
    'compare' => 'IN',
    )
    ;
    Thread Starter wp_user1

    (@wp_user1)

    Debug of working query:

    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:

    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.