I am new to programming and WordPress.

I am working on a project where I am using a custom taxonomy (tag). When I select my tag in the admin panel (post), it automatically gets arranged in alphabetical order.

I'd like to stop that behavior, as I want to display the tags in the order I selected them.

  • How are you selecting your order, and how are you saving it?
    – s_ha_dum
    Jul 26, 2013 at 14:23

2 Answers 2


Here you go: just place this in your functions.php:

 * Sort post_tags by term_order
 * @param array $terms array of objects to be replaced with sorted list
 * @param integer $id post id
 * @param string $taxonomy only 'post_tag' is changed.
 * @return array of objects
function plugin_get_the_ordered_terms ( $terms, $id, $taxonomy ) {
    if ( 'post_tag' != $taxonomy ) // only ordering tags for now but could add other taxonomies here.
        return $terms;

    $terms = wp_cache_get($id, "{$taxonomy}_relationships_sorted");
    if ( false === $terms ) {
        $terms = wp_get_object_terms( $id, $taxonomy, array( 'orderby' => 'term_order' ) );
        wp_cache_add($id, $terms, $taxonomy . '_relationships_sorted');

    return $terms;

add_filter( 'get_the_terms', 'plugin_get_the_ordered_terms' , 10, 4 );

 * Adds sorting by term_order to post_tag by doing a partial register replacing
 * the default
function plugin_register_sorted_post_tag () {
    register_taxonomy( 'post_tag', 'post', array( 'sort' => true, 'args' => array( 'orderby' => 'term_order' ) ) );

add_action( 'init', 'plugin_register_sorted_post_tag' );

(Credit goes to lgedeon on the Wordpress Core Trac)

Now all you need to do is enter the tags in the order you want them to appear.

Note: the above code shows how to do this for post_tag. If you want a different taxonomy, just update the above code with the taxonomy name you want.


When displaying categories you should use

<?php wp_list_categories(array('orderby' => 'ID')); ?>

Instead of ID you can use name,slug,count or term_group. See Codex

  • you didn't got me in admin panel (post) when i select my tag it automatically get arranged in alphabetical order (in admin panel). i want to stop it as i want to display the tags in the order i select.(tag which i select first should come first the tag i select second should come second).@Tolea Bivol Jul 26, 2013 at 12:33
  • 1
    Still dont get it , Some screenshots with some arrows and short explanations on them might clear the question pls Jul 26, 2013 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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