Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Jacob Roman
Jacob Roman
22,640 Points

ACF Relationship field filter

I have the following code set up but I need to filter it by a custom taxonimy that I have set up for these post. Any suggestions on how I would set up that filter? Its not really using the WP_Query so wondering if there is a way to filter if not using WP_Query and $args

            <div id="masonry-loop" >


            <?php 

            $posts = get_field('cars_under_this_group');

            if( $posts ): ?>
                <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
                    <?php setup_postdata($post); ?>


                    <div class="masonry-entry small-6 columns singleGroup">
                        <div style="background: #ffffff; border: 2px solid #333333; margin: 0 0 20px 0;">
                    <?php 

                    $posted = get_field('car_under_id');

                    if( $posted ): ?>
                        <div class="row">
                        <?php foreach( $posted as $p ): // variable must NOT be called $post (IMPORTANT) ?>
                            <div class="small-6 columns">
                                <a class="glow" href="<?php echo get_permalink( $p->ID ); ?>">
                                    <div class="productListThumb" style= "background:url(<?php the_field('thumb_image', $p->ID); ?>) no-repeat center 30%; display:inline-block; width: 100%; height: 155px; background-size: 97%; margin: 10px 0;"></div>
                                </a>
                            </div>
                        <?php endforeach; ?>
                        </div>
                    <?php endif; ?>
                    <div class="row" style="padding: 0 30px 15px;">
                        <h2 style="margin: 0;"><?php the_field('name_of_rcs'); ?></h2>
                        <p style="margin: 0;"><b><?php the_field('detailed_title'); ?></b></p>
                        <p style="margin: 0;"><?php 
                                $age = get_field('age_group');

                                if( $age == '8+') {
                                    echo '<a href=" ' . get_site_url() . '/ages/8/">' . 'Ages: ' . $age . '</a>';
                                } elseif ( $age == '6+') {
                                    echo '<a href=" ' . get_site_url() . '/ages/6/">' . 'Ages: ' . $age . '</a>';
                                } elseif ( $age == '4+') {
                                    echo '<a href=" ' . get_site_url() . '/ages/4/">' . 'Ages: ' . $age . '</a>';
                                } else {
                                    echo 'Ages: ' . $age;
                                }
                                ?></p>
                    </div>
                </div>
                    </div>
                <?php endforeach; ?>
                <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
            <?php endif; ?>
        </div>