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


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 ?


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:



  • ->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.