Home › Forums › Front-end Issues › wp_query filtering is not applying to repeater
Hey
I have a wp_query which displays CPT posts grouped by custom taxonomy. I have also a simple filtering form which should filter displayed posts. While the loop itself works the way i wanted, i have still problems with filtering. The issue is following – I’m displaying posts in this way:
Taxonomy 1
– post A
— (repeater subfield 1, subfield 2..)
— (repeater subfield 1, subfield 2..)
– post B
— (repeater subfield 1, subfield 2..)
— (repeater subfield 1, subfield 2..)
how to assign arguments also to repeater subfields to display posts after filtering in this matter:
Taxonomy 1
– post A
— (repeater subfield 1, subfield 2..)
The code looks as follows:
<?php
if (is_page(29557) ):$childno = '205';
elseif (is_page(29640) ):$childno = '206';
endif;
$args = array(
'child_of'=> $childno,
'childless' => true
);
$taxonomy_terms = get_terms('typ', $args);
if($taxonomy_terms) {
foreach($taxonomy_terms as $taxonomy_term) {
$metaquery = array('relation' => 'AND');
if(isset($_GET['obszar']) && $_GET['obszar'] != '')
{
$taxquery[] = array(
'taxonomy' => 'kategoria',
'field' => 'slug',
'terms' => $_GET["obszar"],
);
}
if(isset($_GET['firma']) && $_GET['firma'] != '')
{
$metaquery[] = array(
'compare' => '=',
'key' => 'terminy_warsztatow_$_firma',
'value' => $_GET["firma"],
);
}
if(isset($_GET['lokalizacja']) && $_GET['lokalizacja'] != '')
{
$metaquery[] = array(
'compare' => '=',
'key' => 'terminy_warsztatow_$_wojewodztwo',
'value' => $_GET["lokalizacja"],
);
}
if(isset($_GET['data']) && $_GET['data'] != '')
{
$metaquery[] = array(
'compare' => '=',
'key' => 'terminy_warsztatow_$_data',
'value' => $_GET["data"],
);
}
$args_main_query = array(
'post_type' => 'opencourses',
'posts_per_page' => -1,
'meta_query' => $metaquery,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'typ',
'field' => 'slug',
'terms' => array( $taxonomy_term->slug ),
'operator' => 'IN'
),
$taxquery
)
);
$query = new WP_Query( $args_main_query );
if ( $query->have_posts() ) : ?>
<h4 class="term_blok_szkoleniowy"><?php echo $taxonomy_term->name; ?></h4>
<?php while ( $query->have_posts() ) : $query->the_post();
if (have_rows('terminy_warsztatow')) : $i = 0; while (have_rows('terminy_warsztatow')) : the_row(); ?>
<div class="row">
<div class="col-sm-12">
<span><img src="<?php the_sub_field('logotyp') ?>" alt="<?php the_sub_field('lokalizacja') ?>"></span>
<span><i style="opacity: .6;" class="glyphicon glyphicon-time"></i><?php the_sub_field('data') ?></span>
<span><i style="opacity: .6;" class="glyphicon glyphicon-map-marker"></i><?php the_sub_field('lokalizacja') ?></span>
</div>
</div>
<?php endwhile; endif;
endwhile;
wp_reset_postdata(); // so nothin' weird happens to other loops
endif;
}
}
?>
I am not sure I understand what you are trying to accomplish.
So, you have a list of terms.
For each term you create a query in order to fetch a list of posts.
For each post you fetch multiple repeaters.
For each repeater… Well, what is the content of these repeaters, and where do the filters come in?
In any case, if you aim to filter posts after they have been fetched by the query, generally it is a good idea to iterate the query results with $query->the_post()
and store the posts in another array for further processing, instead of printing them as they come.
The topic ‘wp_query filtering is not applying to repeater’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.