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 have custom taxonomy that list terms under "series" that contain posts that are also present in terms under "media_type" and where media_type is term_id 16.

I want to order the list by the term_order column in the terms table but it is not working. What am I doing wrong?

Thanks!

    $q_result = $wpdb->get_col("SELECT DISTINCT {$wpdb->terms}.name FROM {$wpdb->terms}
            INNER JOIN {$wpdb->term_taxonomy} ON {$wpdb->term_taxonomy}.term_id = {$wpdb->terms}.term_id
            INNER JOIN {$wpdb->term_relationships} ON {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id
            WHERE {$wpdb->term_taxonomy}.taxonomy = 'series' AND {$wpdb->term_relationships}.object_id IN (
            SELECT object_id FROM {$wpdb->term_relationships}
            INNER JOIN {$wpdb->term_taxonomy} ON {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id
            WHERE {$wpdb->term_taxonomy}.taxonomy = 'media_type' AND {$wpdb->term_taxonomy}.term_id = '16'
            ORDER BY {$wpdb->terms}.term_order
);");
share|improve this question
    
This is an SQL question. –  vancoder Apr 12 '13 at 17:44
    
Does in not belong here? –  izharbuen Apr 12 '13 at 17:46
    
You might get a better repsonse on stackoverflow.com –  vancoder Apr 12 '13 at 17:49
    
in this table {$wpdb->terms} do you have the term_order coloumn ?? –  M Khalid Junaid Apr 12 '13 at 18:58
    
This is clearly off-topic, despite the flag being rejected. It is an SQL question, that is (to quote FAQ) not specific to WordPress (even if they happen in its context) –  vancoder Apr 12 '13 at 19:16
show 2 more comments

1 Answer 1

In your case you are referring ORDER BY {$wpdb->terms}.term_order and as default in wordpress wp_terms table don't have this column the term_order column resides in the wp_term_relationships table and you are referring wp_terms table to ORDER BY this column which is not is present in that table instead of this you have to do something like this

$q_result = $wpdb->get_col("SELECT DISTINCT {$wpdb->terms}.name FROM {$wpdb->terms}
        INNER JOIN {$wpdb->term_taxonomy} ON {$wpdb->term_taxonomy}.term_id = {$wpdb->terms}.term_id
        INNER JOIN {$wpdb->term_relationships} ON {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id
        WHERE {$wpdb->term_taxonomy}.taxonomy = 'series' AND {$wpdb->term_relationships}.object_id IN (
        SELECT object_id FROM {$wpdb->term_relationships}
        INNER JOIN {$wpdb->term_taxonomy} ON {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id
        WHERE {$wpdb->term_taxonomy}.taxonomy = 'media_type' AND {$wpdb->term_taxonomy}.term_id = '16'
        ORDER BY {$wpdb->term_relationships}.term_order ASC
)");
share|improve this answer
    
I went into phpMyAdmin and the wp_terms table has a column called term_order. I'm using a plugin the assign the numbers to the terms. –  izharbuen Apr 12 '13 at 19:47
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.