Support

Account

Home Forums General Issues Query filtering shows all posts instead specific post

Helping

Query filtering shows all posts instead specific post

  • Hi ACF Team,

    On specific page I’m displaying posts from my CPT („opencourses”). Posts from this specific CPT are grouped by custom taxonomy („kategoria”). And this part works. At the same page I have four different select fields to filter the query. One dropdown is dedicated to filtering by mentioned taxonomy, rest of them are related to repeater subfields. I’ve managed to populate select fields with proper data. And this part works also great.

    What I’m missing is one thing – when I’m filtering my posts, it shows entire group of posts instead THE SPECIFIC post. Hopefully below example will be more descriptive – what I get currently:

    TAXONOMY_CHILD_1
    – Post 1
    – Post 2
    – Post 3
    – Post 4

    What I want to get:

    TAXONOMY_CHILD_1
    – Post 3

    It’s crucial to me just to highlight the specific posts. Taxonomy Childs are in my example types of courses. Inside specific type I have bunch of courses with different timing, location, price, so showing them at the same time is pointless.

    Entire code can be found here:

    
    <?php
    
        $taxonomy = 'typ';
    
            if (is_page(29557) ):
                $childno = '205';
            
            elseif (is_page(29640) ):
                $childno = '206';
    
            endif;										
                                    
        $args = array(
            'child_of'=> $childno,
            'childless' => true  					
        );
    
        $taxonomy_terms = get_terms($taxonomy, $args);
    
        
        if($taxonomy_terms) {
            foreach($taxonomy_terms as $taxonomy_term) {
                
                $taxquery = array('relation' => 'AND');
                $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',
                    "$taxonomy" => $taxonomy_term->slug,
                    'post_status' => 'publish',
                    'posts_per_page' => -1,	
                    'fields' => 'all',
                    'tax_query' => $taxquery,
                    'meta_query' => $metaquery,
                );
    
                $query = new WP_Query( $args_main_query );
            
                if ( $query->have_posts() ) : ?>
    
                <?php $color = get_field('blok_szkoleniowy_kolor', $taxonomy_term); ?>
    
                <div class="term_anchor" id="<?php echo $taxonomy_term->slug; ?>"></div>
                <h4 class="term_blok_szkoleniowy"><span class="spacer" style="background:<?php echo $color; ?>"></span><?php echo $taxonomy_term->name; ?></h4>
    
                    <?php while ( $query->have_posts() ) : $query->the_post(); ?>
    
                    <div class="row">
                        <div class="col-md-12">
                            <div class="coursWrapper">
                        
                                <div class="visibleInfoCourses" style="border-left: 5px solid <?php echo $color; ?>">
                                        <div class="row">
                                            <div class="col-sm-7">
                                                <p><a href="<?php the_permalink() ?>"><?php the_title() ?></a>
                                                <?php if (get_field('nowosc')) : ?><span class="labelItem labeImNew">Nowość</span><?php endif ?>
                                                <?php if (get_field('new_form')) : ?><span class="labelItem labeImNewForm">Nowa formuła</span><?php endif ?>
                                                <?php if (get_field('new_date_info')) : ?><span class="labelItem labeImNewDate">Zmiana terminu</span><?php endif ?>
                                                </p>
                                            </div>
                                            <div class="col-sm-5">
                                                <div class="buttonsHereRight">
                                                    <button class="btnBorderGrey btn-lean-sm">Terminy warsztatów</button>
                                                </div>
                                            </div>
                                        </div>																										
                                </div>
    
                                <div class="InvisibleInfoCourses" style="border-left: 5px solid <?php echo $color; ?>">
                                    <?php if (have_rows('terminy_warsztatow')) : $i = 0; ?>
                                        <div class="TerminySzkolen" style="padding: 0;">
                                            <?php while (have_rows('terminy_warsztatow')) : the_row();
                                                $i++;
                                                $hotele = get_sub_field('polecane_hotele');
                                                $zapisy = get_sub_field('stan_zapisow'); ?>
                                                <div class="InvisibleInfoCoursesDetails" <?php if ($zapisy == 'Sprzedane') : echo " style='opacity:.6;'";endif; ?>>
                                                    <div class="row">
                                                        <div class="col-sm-10">
                                                            <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>
                                                            <span><i style="opacity: .6;" class="glyphicon glyphicon glyphicon-list-alt"></i><?php echo $zapisy; ?></span>
                                                        </div>
                                                        <div class="col-sm-2">
                                                            <div class="buttonsHereRight">
                                                                <!-- <a class="btn-lean btn-lean-sm" target="_blank" download="Formularz zgłoszeniowy" href="<?php the_sub_field('przycisk') ?>" onclick="gtag('event', 'szkolenia', {'event_category' : 'szkolenie-otwarte-lista-szkoleń','event_label' : '<?php the_title() ?> '});" <?php if ($zapisy == 'Sprzedane') : echo " style='display:none'";endif; ?>>Zapisz się</a> -->
                                                                <!-- <a class="btn-lean btn-lean-sm" href="<?php the_permalink(); ?>" onclick="gtag('event', 'szkolenia', {'event_category' : 'szkolenie-otwarte-lista-szkoleń','event_label' : '<?php the_title() ?> '});" <?php if ($zapisy == 'Sprzedane') : echo " style='display:none'"; endif; ?>>Zapisz się</a> -->
                                                                <a class="btn-lean btn-lean-sm" href="<?php the_permalink(); ?>" <?php if ($zapisy == 'Sprzedane') : echo " style='display:none'"; endif; ?>>Zapisz się</a>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            <?php endwhile; ?>
                                        </div>
                                    <?php endif ?>
                                </div>
                            </div>
                        </div>
                    </div>
                        
                    <?php endwhile; ?>
    
                    
    
                <?php wp_reset_postdata(); // so nothin' weird happens to other loops
                endif;
            }
        }
        
    ?>
  • Anybody? I have no clue how to solve that.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Query filtering shows all posts instead specific post’ is closed to new replies.