Displaying Posts Using a Custom Query with a Custom Field and a term_id (2 posts)

  1. Nego90
    Posted 3 years ago #

    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!!!

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    Why aren't you using WP_Query?

Topic Closed

This topic has been closed to new replies.

About this Topic