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 display a list of posts in a category of a taxonomy using a Custom Field. Here's my code:

if($current_term->term_id=='143') {     
   $querystr = "  SELECT wposts.*
        FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta, $wpdb->terms wpterms
        WHERE wposts.ID = wpostmeta.post_id
        AND wpostmeta.meta_key = 'apecard'
        AND wpostmeta.meta_value = 'on'     
        AND wpterms.term_id  =  '143'
        AND wposts.post_status = 'publish'
        AND wposts.post_type = 'locali'
        ORDER BY wposts.post_date DESC ";
 .....

The results display all posts that have meta_key='apecard' in every category of the taxonomy. But I want to display that posts only in the category with term_id=143. Thanks you!!!

share|improve this question
add comment

1 Answer 1

$args = array(
    'post_type' => 'locali',
    'meta_query' => array(
        array(
            'key' => 'apecard',
            'value' => 'on',
        )
    ),
    'tax_query' => array(
        array(
            'taxonomy' => 'yourtaxonomy',
            'field' => 'id',
            'terms' => array('143')
        )
    )
);
$postslist = get_posts( $args );
share|improve this answer
1  
it works!!!!!!!!!!!!!!!!!! Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!‌​!!!!!!!!! –  Nego90 Apr 5 '12 at 10:51
    
@Nego90 you can accept answer..... –  Rajeev Vyas Apr 5 '12 at 10:53
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.