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.

Ok, so i have a Custom Post Type called "Services". This custom post type has a taxonomy called "Areas" and there's 5 terms in that taxonomy.

Let's say I have 10 posts on "Services" and there's 5 posts in the term "Painting" and 5 more on the term "Photography".

I need to be able to query posts from "Services" but instead of showing those 10 posts, only show 5 associated to "Painting".

At the moment i'm able to query by taxonomy and terms, but that will show all of the posts from "services" with no filter by term.

Basically query post by post_type from the term I choose.

Any help would be awesome. Thanks.

<ul id="service-list">
<?php 
        $args = array('tax_query' => array( array('taxonomy' => 'areas', 'field' => 'slug','terms' => 'painting')));

        $the_query = new WP_Query( $args );

        if($the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();

        ?>

    <li class="service">
        <h2><?php the_title(); ?></h2>
        <?php the_content(); ?>
    </li><!-- /.service -->

<?php endwhile; else: ?>

    <p>Nothing Here.</p>

<?php endif; wp_reset_postdata(); ?>

</ul><!-- #service-list -->

So if I could just specify on the $args from which post type to get the posts from this would be solved.

share|improve this question
    
Ok, so it looks like I over thought all of this and the solution was really simple: –  Rise Mar 14 '12 at 17:55
    
Please mark your answer as correct or delete the topic. –  AlxVallejo Mar 14 '12 at 17:57
    
I need to wait 7 hours to post the solution :( –  Rise Mar 14 '12 at 17:58

1 Answer 1

up vote 9 down vote accepted

This is the answer to the question :)

<?php 

$args = array(
    'post_type'=> 'services',
    'areas'    => 'painting',
    'order'    => 'ASC'
    );              

$the_query = new WP_Query( $args );
if($the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); 

?>
share|improve this answer

protected by toscho Jul 27 at 8:29

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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