0

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
            ));
1

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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