1

In D7, I'm trying to set up a custom menu that is ordered by the weight of the node->path ("weight" field in table menu_links). How can I access the node's path's weight value in my query so it can be ordered correctly? This is what I had but was shot down very quickly:

    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'node')
    ->propertyCondition('status', 1)
    ->fieldCondition('field_meeting', 'value', $meetid, '=')
    -> propertyOrderBy('weight','ASC')    
    ->addMetaData('account', user_load(1)); // Run the query as user 1.
    $result = $query->execute();
  • 1
    You can't without altering the query at a later stage (hook_query_alter()). You can only get entity properties and fields by default with an EntityFieldQuery, nothing that would require joining in other tables – Clive Mar 2 '13 at 11:03
  • Thanks very much Clive! When you say later stage, any way I run the order immediately after the execute? Looking at the query_alter code I am not quite sure if I have to call it outside my module? – longboardnode Mar 2 '13 at 18:47
2

I ended up using db_query JOIN to get the info straight from the database:

$sql = "SELECT menu_links.link_path, menu_links.link_title, menu_links.weight, node.nid 
        FROM menu_links
        JOIN node.nid
        ON menu_links.link_path LIKE CONCAT('node/', node.nid)
        ORDER BY menu_links.weight ASC";
$result = db_query($sql);
|improve this answer|||||

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.