Hello, I’ve got the following problem while querying with repeater subfields:
My aim is to query posts where the subfield ‘age’ (leeftijd) (which is a radio button) is ‘4-6’, ‘7-9′, ’10-12’, or ‘4-12’.
Then it should also query whether it has a subfield ‘subject’ (onderwerp) (which are checkboxes), like ‘inrichten’, ‘communicatie’, and ‘regels’.
So for example I have a post where the age is ‘7-9’, and the subjects in that row are ‘inrichten’ and ‘communicatie’. It also has ‘age’: ‘4-6’ and ‘subject’: ‘regels’ (which is why I use a repeater field for this).
It should show the post whether I query on ‘inrichten’ or ‘communicatie’.
I’ll use the following query (with ‘inrichten’):
<?php function my_posts_where( $where ) {
$where = str_replace("meta_key = 'gegevens_%", "meta_key LIKE 'gegevens_%", $where);
return $where;
}
add_filter('posts_where', 'my_posts_where'); ?>
<?php $args = array(
'post_type' => 'spelvormen',
'post_status' => 'public',
'posts_per_page' => '-1',
'order' => 'ASC',
'orderby' => 'title',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'gegevens_%_leeftijd', //radio
'compare' => '=',
'value' => '7-9',
),
array(
'key' => 'gegevens_%_onderwerp', //checkbox
'compare' => 'LIKE',
'value' => 'inrichten',
),
),
);
$query = new WP_Query( $args ); ?>
This works, it shows a post which has both values. The problem, however, I have two more posts (a total of 3), where the third post doesn’t have the subject ‘inrichten’ (where age is ‘7-9’).
But it is still being shown in the frontend, while it shouldn’t. Did I do something wrong in my query? I’m using this for a ajax form where people can select the age and the subject, and then it should display posts which have these values.
The form works, but as I said before, it displays an extra post which should’nt be displayed.