0

I have been using the following line to get all the nodes with a term id

taxonomy_select_nodes($tid);

But now I want to sort the output by weight (field_audio_weight - field I created). How can I achieve the same output using EntityFieldQuery ?

1

Something like:

$query = new EntityFieldQuery()
  ->entityCondition('entity_type', 'node')
  ->fieldCondition('field_taxonomy_reference', 'tid', TERM_ID)
  ->fieldOrderBy('field_audio_weight', 'value', 'DESC');

$results = $query->execute();

Check these articles for more information:

https://www.phase2technology.com/blog/entityfieldquery-let-drupal-do-the-heavy-lifting-pt-1/

https://www.phase2technology.com/blog/entityfieldquery-let-drupal-do-the-heavy-lifting-pt-2/

| improve this answer | |
  • ->fieldOrderBy('field_audio_weight', 'DESC'); should be: ->fieldOrderBy('field_audio_weight', 'value', 'DESC'); – dasj19 Mar 2 '16 at 15:21
  • Ok, edited. I wrote it off the cuff, which is why I linked to the two articles on how to use it and how to extend on it if needed. – Kevin Mar 2 '16 at 15:33

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.