Here’s a complex query which we’ve built using WP_Query. It should:
- Ignore post id 191
AND
- Select all posts with ‘reihenfolge’ <= 18
AND
- Ignore posts without a featured image
AND
- Order them randomly
Here is the code:
$args_projekte = array(
'post_type' => 'projekt',
'posts_per_page' => 18,
'meta_query' => array('relation' => 'AND',
array('post__not_in' => array(191)),
array('meta_key' => 'reihenfolge',
'meta_value_num' => '18',
'meta_compare' => '<='),
array('key' => '_thumbnail_id')
),
'orderby' => 'rand'
);
However, ALL posts are being shown in a random order. 'reihenfolge <=18'
seems to be being ignored.
What are we missing here?
Your
meta_query
is completely wrong. All you parameters inside your arrays is invalid.post__not_in
should be outside yourmeta_query
meta_key
,meta_value_num
andmeta_compare
are all invalid paramters inside ameta_query
. This parameters is used outside ameta_query
You query should look something like this