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'm researching this problem for days without any success... What I want is very simple: to see my custom taxonomy terms sorted by ID on the admin page. I can't believe that something this simple can't be accomplished without plugins.

(I already have a sortable custom column, but it would be important to set the default order as well.)

So far I have found the following two solutions, which doesn't work for some reason:

1) Registering the taxonomy with "sort => true":

register_taxonomy( 'issue', 'post', array( 'hierarchical' => false, 'labels' => $labels, 'public' => true, 'sort' => true, 'args' => array( 'orderby' => 'id' ), 'query_var' => 'issue', 'rewrite' => array( 'slug' => 'issues' ) ) );

Source: http://codex.wordpress.org/Taxonomies#Registering_a_taxonomy

2) Filtering "request" and adding "orderby":

function my_default_orderby( $vars ) {
  $screen = get_current_screen();

  if ( 'edit-issue' == $screen->id ) {
    if ( !isset( $vars['orderby'] ) ) {
      $vars['orderby'] = 'id';
    }
  }

  return $vars;
}
if ( is_admin() )
add_filter( 'request', 'my_default_orderby' );

Source: http://scribu.net/wordpress/custom-sortable-columns.html#comment-4456

share|improve this question
2  
Downvote for the "no Plugins" restriction. –  Chip Bennett Jan 31 '12 at 21:33
add comment

3 Answers

My decision while I made wp theme is do that by javascript: in general.js which included in backend

add_action('wp_head', 'thememakers_theme_wp_head');
function thememakers_theme_admin_head() {
 wp_enqueue_script('thememakers_theme_admin_js', THEMEMAKERS_THEME_URI . '/admin/js/general.js');
}

in that general.js write:

jQuery(document).ready(function() {
//for events
    var event_link=jQuery('.wp-submenu-wrap a[href$="?post_type=event"]').eq(0);
    jQuery(event_link).attr('href', jQuery(event_link).attr('href')+"&orderby=ev_mktime&order=desc");
});

where ev_mktime is custom post meta.

That is all. Simple and power.

share|improve this answer
add comment

You need to take a look at

/core_root/wp-admin/includes/class-wp-terms-list-table.php

and then add an extended class and make use of the WP_list_Table Class and documentation. basically you're overriding the order and orderby in some custom plugin.


Btw: "No Plugins" is never a good idea as plugins may show you how it works in code and therefore be a) a valid answer and b) a good reference or starting point.

share|improve this answer
add comment

How about just using get_terms( 'taxonomy-slug', array( 'orderby' => id,'hierarchical' => 1 ) ); and then iterating through that?

share|improve this answer
    
Thanks for the tip! Unfortunately, the page where I have to reorder the terms is the "edit-tags.php", where the terms are listed in a table. I have no idea how could I rebuild this table with a "get_terms" query. (In other admin customizations I'm already using "get_terms" to list the terms with the proper order.) –  Gabor Barat Jan 31 '12 at 16:32
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.