Move Stand With Israel Under Partners Menu
PHP snippet to programmatically move the Stand With Israel page under the Partners menu item.
<?php
// Move Stand With Israel under Partners menu
add_action('wp_loaded', function() {
// Find Stand With Israel page
$stand_with_israel = get_page_by_path('stand-with-israel');
if ($stand_with_israel) {
$stand_israel_id = $stand_with_israel->ID;
// Find Partners menu item
$args = array(
'post_type' => 'nav_menu_item',
'numberposts' => -1,
'meta_query' => array(
array(
'key' => '_menu_item_object_id',
'value' => get_page_by_title('Partners')->ID,
'compare' => '='
)
)
);
$menu_items = get_posts($args);
if (!empty($menu_items)) {
$partners_menu_id = $menu_items[0]->ID;
// Find Stand With Israel menu item
$args2 = array(
'post_type' => 'nav_menu_item',
'numberposts' => -1,
'meta_query' => array(
array(
'key' => '_menu_item_object_id',
'value' => $stand_israel_id,
'compare' => '='
)
)
);
$stand_items = get_posts($args2);
if (!empty($stand_items)) {
$stand_menu_id = $stand_items[0]->ID;
// Update parent
update_post_meta($stand_menu_id, '_menu_item_menu_item_parent', $partners_menu_id);
error_log('Moved Stand With Israel under Partners');
}
}
}
}, 999);
?>




