Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I´d like to do something like this:

Pages:
1. Sport
2. Business
3. Normal

Custom Category "Car-Types":
1. Audi
2. BMW
3. VW

My custom post type will called "Cars"

I´d like to show the cars by using a custom category like "Car-Type".
How can I filter the content from the custom categories, too and show it?

E. G.: On Page "Sport" should just show the content from "BMW".

<?php $args = array( 'post_type' => 'cars' ); // How can I add a category-filter to this?

$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
    echo '<li>';
    the_title('<h3>', '</h3>');
    the_content();
    echo '</li>';
endwhile; ?>

Thanks

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted
<?php $args = array( 'post_type' => 'cars' ); // How can I add a category-filter to this?
$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'Car-Types',
            'field' => 'slug',
            'terms' => 'Audi'
        )
    )
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
    echo '<li>';
    the_title('<h3>', '</h3>');
    the_content();
    echo '</li>';
endwhile; ?>

http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

share|improve this answer
    
Great. Thanks for sharing this code. –  ogni Aug 4 '12 at 11:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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