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?


Hopefully this will help out.

$args = array
    'post_type' => 'cars',
    'tax_query' => 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()):?>
        <?php while($car_query->have_posts()): $car_query->the_post();?>
                <a href="<?php the_permalink();?>"><?php the_title();?></a>
        <?php endwhile; wp_reset_postdata(); ?>
<?php endif;?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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