0

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

| improve this question | | | | |
2
<?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

| improve this answer | | | | |

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.