0

I created a taxonomy vocabulary and added some taxonomy terms to it. How can i sort alphabetically the listing of terms in taxonomy vocabulary page. The same sorting needs to reflect in content type fields when this vocabulary is added as term reference.

3
  • If default sorting is not good enough for you, why don't you switch to Views?
    – Mołot
    May 29, 2015 at 13:49
  • List the taxonomy, then 'reset to alphabetical'. May 29, 2015 at 16:14
  • I need to remove rest to alphabetical button. Its drupal core vocabulary page. Do I need to edit drupal core term listing query. Or any drupal hooks are available. On every addition of new term,the list need to sort alphabetically
    – drup
    May 30, 2015 at 4:25

2 Answers 2

3

I hijacked the code from /modules/taxonomy/taxonomy.admin.inc that runs when you click "Reset to alphabetical". I tweaked it a bit and you can place this code in a custom module and it will run every time you insert a taxonomy term.

/**
 * Implements hook_taxonomy_term_insert()
 */
function YOURMODULE_taxonomy_term_insert($term) {

  $vocabulary = taxonomy_vocabulary_load($term->vid);
  $tree = taxonomy_get_tree($vocabulary->vid);

  if($vocabulary->machine_name = 'MACHINE_NAME_YOU_WANT_TO_FORCE_ORDERING') {
    //Make sure the taxonomy doesn't have terms with two parents
    if ($vocabulary->hierarchy < 2 && count($tree) > 1) {
      $params = array(
        'values' => array(
          'vid' => $term->vid, 
          'name' => $vocabulary->name, 
          'machine_name' => $vocabulary->machine_name, 
        ), 
      );

      taxonomy_vocabulary_confirm_reset_alphabetical_submit(NULL, $params);
    }
  }
}

If you want it to apply to all vocabularies, you can remove the IF statement on line 7. Good luck!

0

Simply scroll to bottom and click on reset alphabetical at /admin/structure/taxonomy/, do that after doing changes, you maybe be able to have a cron run and do this every few hours or so.

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.