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 want to select some tags with the same term_group, I tested it in phpadmin, the query get the correct result, but once add $wpdb flavor, it returns an empty array. Any advice?

$primary_tag_id = // a function to return term_group, result is 3, comfirmed
    $terms = $wpdb->get_col( $wpdb->prepare(
            "SELECT name
            FROM $wpdb->wp_terms
            WHERE term_group = %d
            ORDER BY name ASC", $primary_tag_id
            ));
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Try this, it worked for me:

    global $wpdb;
    $terms = $wpdb->get_col( $wpdb->prepare(
            "SELECT name
            FROM {$wpdb->terms}
            WHERE term_group = %d
            ORDER BY name ASC", primary_tag_id
            ));

What you are after is $wpdb->terms not $wpdb->wp_terms

share|improve this answer
    
Thanks! Got the result now. –  Jenny Jan 12 '12 at 11:41
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.