1

How can I order by weight using node_lode_multiple and the weight module ?

   <div id="photos_inner">
         <?php 
           $type = "staff";
           $nodes = node_load_multiple(array(), array('type' => $type)); 
           foreach($nodes as $staff):
         ?>
1
  • You need to give us more information in order to help you. – pbonnefoi Nov 5 '14 at 9:40
2

No, results of node_load_multiple() are in the order in which the node IDs were passed to it in the first place. There are no other sorting options through that function.

The weight module doesn't appear to have an API for this, so you'll need to create a query that joins the node and weight_weights tables to get the nids in the right order, then pass them to node_load_multiple().

1
  • node_load_multiple() return an array of node objects indexed by nid. – Rajesh Vishwakarma Dec 19 '19 at 15:13
2

In addition to Clive's answer, you can do it this way:

$type = 'your_content_type';
$query = db_select('node', 'n');
$query->join('weight_weights', 'w', 'n.nid = w.entity_id');
$query->fields('n', array('nid'))
  ->condition('type', $type)
  ->orderBy('w.weight', 'ASC');
$nids = $query->execute()->fetchCol();
$nodes = node_load_multiple($nids);
1

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.