I am not familiar with the Drupal 7 database API. I want to alphabetized a menu.
Can anyone help me write a database query to retrieve all the menu item links of a certain parent (plid = 228) and order ascending by title? Within that result set, can anyone help me write a database update method to update each menu item's weight sequentially (counter starts at 0 and increments)?


Something like this should work, but I have not tested this code. Please comment on this if you have questions.

$result = db_select('menu_links', 'ml') 
  ->fields('ml', 'mlid')
  ->condition('ml.plid', $plid, '=')

foreach ($result as $row) {
    ->fields(array('weight' => $i))
    ->condition('mlid', $row->mlid)

At this point they would all be ordered by title, and you could print the menu wherever needed.

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