Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3487804
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:11:37+00:00 2026-05-18T11:11:37+00:00

I want to change the parent of a menu tree on a node update.

  • 0

I want to change the parent of a menu tree on a node update. I’m using the module named “rules” to access the update event and I have this code as follows:

if ($node->taxonomy[1] == "1") {
    $plid = 440;
} else if ($node->taxonomy[1] == "2") {
    $plid = 379;
}
if($plid) {
    db_query("UPDATE {menu_links} SET plid='".$plid."', p1='".$plid."' WHERE link_path='"."node/".$node->nid."'");
}

The problem is that this $node which is updated also has some child menu items under it, in the primary menu and when I update the node to change the parent, its children just end up one level higher and don’t get moved with current menu item. Is there an easy way to move a whole menu tree from one parent menu item to another?

I want this,

–parent1

—child1

—sub-child1

—sub-child2

–parent2

to be this:

–parent1

–parent2

—child1

—sub-child1

—sub-child2

Can you help me? Is there a Drupal-way of doing this? =)

I know that this code makes a lot of assumptions but I need it just for one specific case

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:11:38+00:00Added an answer on May 18, 2026 at 11:11 am

    I figured it out by experimenting with the API:

    <?php
        $result = db_query("SELECT mlid FROM {menu_links} WHERE link_path='%s'", "node/".$node->nid);
        $oldItem = db_fetch_array($result);
        $oldLinkItem = menu_link_load($oldItem[mlid]);
        $oldLinkItem[plid] = $plid;
        menu_link_save($oldLinkItem);
    ?>
    

    Just needed to figure out that I didn’t have to deal with those “p0” to “p8” when saving the new menu item. Drupal seems to automatically move the children. By the way, I could use a more reliable way of getting mlid of nodes menu item.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have many div's with the same background image and i want change this
I want to change the behaviour of the editable ComboBox. This is the behaviour
I'm using that jQuery Vertical Menu Library www.dynamicdrive.com/dynamicindex1/ddsmoothmenu.htm I want to accomplish the selection
I want to change the order of two rows in a table. I have
To be Google friendly, I want to change this script a little bit. I
I am using prettyCheckboxes and I want to change it so that the div
I want to create a tree structure in my program. Right now I have
I have this fiddle: http://jsfiddle.net/tatygrassini/tZBXe/ Horizontal dropdown menu with a 1 level deep submenu.
I have the following HTML markup and I want the menu div tag to
I have a class in the main project I don't want to change. class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.