Display CPT posts based on specific taxonomy

Question

So I have a custom post type called opencourses. There is a custom taxonomy called typ. Obviously inside I have a multiple terms divided into two main pillars (production and services).

Unfortunately my current code displays ALL posts from the custom post.

What I’m trying to achieve is to show on page dedicated to production only production terms/posts, and the same thing for services.

The code is following

            <div class="listaWarsztatow" id="listaWarsztatow">
                            <?php

                                $taxonomy = 'typ';

                                $args = array(
                                    'orderby' => 'title',
                                    'order' => 'ASC',
                                    'childless' => true                         
                                );

                                $taxonomy_terms = get_terms($taxonomy, $args);
                                if($taxonomy_terms) {
                                    foreach($taxonomy_terms as $taxonomy_term) {
                                        $args = array(
                                            'post_type' => 'opencourses',
                                            "$taxonomy" => $taxonomy_term->slug,
                                            'post_status' => 'publish',
                                            'posts_per_page' => -1,

                                        );
                                        $query = new WP_Query( $args );

                                        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;
                                    }
                                }

                            ?>
                            </div>

What here is wrong?

0
, , , Pawel Skaba 12 months 0 Answers 78 views 0

Leave an answer