Viewing 9 replies - 1 through 9 (of 9 total)
  • get_the_terms() does not appear to accept a third parameter.

    Thread Starter dadastudio

    (@dadastudio)

    ok. I meant wp_get_object_terms. Sorry.

    $terms=wp_get_object_terms($post->ID,"tax",array("orderby"=>"term_order"));

    According to Codex:

    Argument Options:
    Other supported values include ‘count’, ‘slug’, ‘term_group’, ‘term_order‘, and ‘term_id’.

    It seems that ordering by term_order doesn’t work. Use of the rest of argument options gives correctly ordered array of objects… Is this a bug?

    Hi,
    I’m not sure if this is a bug or not, I checked the function and it should work with ‘term_order’ also so it’s not a codex mistake to verify this you can run the fallowing query :
    "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tr.object_id IN ($object_ids) $orderby $order";
    against your sql database (this is the query that wp_get_object_terms is using to populate the variables). All you need to do is to replace the variables with your data (taxonomies and so on) and check the results.
    If you want to check the code yourself you have it here at line 1867 | the query is at line 1944
    I’m really waiting for a response from you …
    Thank you
    Regards

    This function returns list of terms if it exist , if it isn’t exist it return error , just use this code
    save returned value in $result and pass that value below :
    if ( is_wp_error( $result ) ) {
    $error_string = $result->get_error_message();
    echo ‘<div id=”message” class=”error”><p>’ . $error_string . ‘</p></div>’;
    }

    Thread Starter dadastudio

    (@dadastudio)

    jnhghy,

    I ran this query and I realized that tables wp_term_relationships and wp_terms both have term_order field.

    wp_get_object_terms gets post_order from wp_term_relationships while I have all values in wp_terms

    taxonomy.php:

    #1914 $orderby = ‘tr.term_order’; where tr is for wp_term_relationships

    I changed a source and now it’s working as I wanted but I need to workaround this. I cannot change a source of wordpress every time. Maybe should I use a better plugin for setting terms order.

    Well,
    I don’t seem to have term_order in wp_terms, checked several wordpress installs and they are all missing the term_order field in the wp_terms table. I don’t think that the term_order column is a wordpress default column in the wp_terms table of the database.
    You are right, changing wordpress core is not a suitable solution, it gets overwritten with each update.
    Why can’t you use term_order from the wp_term_relationship table? are you using a specific plugin that uses/created ‘term_order’ in the wp_terms table? is this database coming from an old version of wordpress?
    Regards

    Thread Starter dadastudio

    (@dadastudio)

    jnhghy,

    term_order in wp_terms has been created by a plugin, I guess… So it becomes quite obvious that wordpress cannot query this.

    Thread Starter dadastudio

    (@dadastudio)

    anyway, thanks everybody for help.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘get_the_terms ordered by term_order’ is closed to new replies.