Support

Account

Home Forums Front-end Issues wp_query filtering is not applying to repeater

Unread

wp_query filtering is not applying to repeater

    • pawciak

    • January 10, 2020 at 1:11 am

    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;
            }
        }
    ?>
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.