0

I'm trying to add a snippet in my Wordpress sidebar which displays a list of links to posts which match a criteria.

I'm using a Custom Post Type cars and a taxonomy car-types and I'd like to display a list of links to cars which are part of the car-types taxonomy.

So in short. Display list of links where post is a custom post type called cars and the car-types taxonomy is SUV

Is there a way of doing this please?

1 Answer 1

1

Hopefully this will help out.
https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

<?php
$args = array
(
    'post_type' => 'cars',
    'tax_query' => array
     (
        array
        (
            'taxonomy' => 'car-types',
            'field'    => 'slug', //or name or term_id
            'terms'    => 'suv',
        )
     )
);
$car_query = new WP_Query($args);?>
<?php if($car_query->have_posts()):?>
    <ul>
        <?php while($car_query->have_posts()): $car_query->the_post();?>
            <li>
                <a href="<?php the_permalink();?>"><?php the_title();?></a>
            </li>
        <?php endwhile; wp_reset_postdata(); ?>
    </ul>
<?php endif;?>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.