Support » Plugins » cant select specific categories using $wpdb->

  • Hi there,
    I am currently using SELECT $wpdb->posts.* to get my pending posts that have a specific meta_key value. but it is not adding my parameter to further sift by a specific category. It works until i add my categories parameter..
    my code is below:

    $querystr = "
        SELECT $wpdb->posts.*
        FROM $wpdb->posts, $wpdb->postmeta
        WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
        AND $wpdb->postmeta.meta_key = 'tentativeastatus'
        AND $wpdb->postmeta.meta_value = '" . $tentativeastatusc . "'
        AND $wpdb->posts.post_status = 'pending'
    	AND $wpdb->term_taxonomy.taxonomy = 'category'
    	AND $wpdb->term_taxonomy.term_id IN(5,18,19,20)
        AND $wpdb->posts.post_type = 'post'
        AND $wpdb->posts.post_date < NOW()
        ORDER BY $wpdb->posts.post_date DESC
     ";
    $pageposts = $wpdb->get_results($querystr, OBJECT);

    and it functions, until i add my categories ‘AND’

    AND $wpdb->term_taxonomy.taxonomy = 'category'
    	AND $wpdb->term_taxonomy.term_id IN(5,18,19,20)

    remove those two lines, and it functions..
    Thanks again,

  • The topic ‘cant select specific categories using $wpdb->’ is closed to new replies.