5

for some reason the sort criteria by taxonomy term field do not work properly.

This is the view:
enter image description here
Here you can see the field I order by. The options of the field is the default. Only one taxonomy term per node. enter image description here And this is the result: enter image description here

As you can see the '2005' node is at the end and not a the start of the view's result. I have no idea why this happened. I tryed to delete the node and create a new one, delete the taxonomy term and recreate this but nothing happned.

Can someone help me to understand what is happening? I do not want to add queue module and order the view by queue order..

NEWS

SELECT ... ORDER BY field_data_field_edizione_field_edizione_tid ASC
The view order by tid and not by weight T___T Now I understand what is the problem.. how can I create a new views sort criteria?

2

Solved! I create a relationship beetween the nome and the taxonomy term using the term weight to order the nodes ^^ Now it works!

Thank you Mołot to let me see the SQL query ^^

enter image description here

  • yes. sort by weight :) – Yusef Nov 30 '14 at 6:15
  • @Shyghar for some reason it doesn't work for me :( – lephleg Apr 4 '16 at 8:55
1

Sorting (numerically) by weight is not the same thing as sorting (alphabetically) by name. Weight for taxonomy terms can be made to be equivalent to an alphabetical list, but in some cases the weight is different. (Weight also controls the order of the terms as they appear in a select list widget on a term reference field.)

To sort the view by term Name you need to add a relationship from the node to the term, and then add sort criteria for term Name.

Though the solution above is how it should work in theory, I have also been having trouble getting that to work in practice. (I suspect there is a bug in the term name views handler.)

-1

You can also do this without creating a view. Within your template.php file, you can do the following.

function yourthemename_preprocess_page(&$vars) {
    if($vars['node']->field_services['und']) {
    // Create an Array
    $termresult = array();
    // Iterate through the tids, load their names and add to our array
    foreach ($vars['node']->field_services['und'] as $termobject) {
      $term = taxonomy_term_load($termobject['tid']);
      array_push($termresult, $term->name);
    }
    // Sort the returned array
    sort($termresult);
    // Print them out based on our new sorting.
    foreach ($termresult as $termobject) {
      $vars['terms'] .= "<li>".$termobject."</li>";
    }
  } else {
    $vars['terms'] = "";
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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