2

I need to order my news by their importance value (1, 2 or 3) which is in the field field_importance and the date they are published. So I would need to order my news by this calculation: created * field_importance and I haven't figured out a way to do it with EntityFieldQuery. If someone knows a way to do it without EntityFieldQuery, that's equally good. This is my code so far:

$query->entityCondition('entity_type', 'node')
      ->propertyCondition('status', 1)
      ->propertyCondition('type', array('news'))
      ->propertyOrderBy('created', 'DESC');
1

If you don't have to pull in a whole bunch of linked entity stuff, just run a regular db_query() joining your "importance" field table to your node table.

$query = "SELECT nid, (created * field_importance_value) AS weight FROM node n JOIN field_data_field_importance f ON f.entity_id = n.nid WHERE type = 'news' AND status = 1 ORDER BY weight DESC"; $result = db_query($query); // Add foreach loop here...

I'm just guessing the importance table name and field name from your OP.

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.