I want to get the parent object(menu object but not ID, not post object) in my nav walker or walker edit class?
I need to get the parent menu item's object in my extended Walker class, because I will use the relationship to add some custom settings for each menu items on the walker edit page.
I can get the parent ID of a current item by $item->menu_item_parent
, but I need no id but an object. And I also can get WP_Post object of the parent item by get_post( $item->menu_item_parent );
in walker class, but it only returns a normal WP_Post object which is not including any information about menu_item_parent
(this is because that I need to get all the ancestors and the information of the current item).
The following returns ''(null):
wp_get_nav_menu_items($item->menu_item_parent, array('post_type' => 'nav_menu_item', 'output' => OBJECT));
print_r($item);
WP_Post Object
(
[ID] => 7490
[post_author] => 1
[post_date] => 2015-07-19 18:48:11
[post_date_gmt] => 2015-07-19 18:48:11
[post_content] =>
[post_title] => Single Forum
[post_excerpt] =>
[post_status] => publish
[comment_status] => open
[ping_status] => closed
[post_password] =>
[post_name] => single-forum
[to_ping] =>
[pinged] =>
[post_modified] => 2016-02-27 16:31:08
[post_modified_gmt] => 2016-02-27 16:31:08
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://xxxxxx.com/?p=7490
[menu_order] => 53
[post_type] => nav_menu_item
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
[db_id] => 7490
[menu_item_parent] => 7493
[object_id] => 7490
[object] => custom
[type] => custom
[type_label] => Custom Link
[title] => Single Forum
[url] =>
[target] =>
[attr_title] =>
[description] =>
[classes] => Array
(
[0] =>
)
[xfn] =>
)
=> This is the object structure that I want to get.
and
global $post;
print_r(get_post( $item->menu_item_parent ));
WP_Post Object
(
[ID] => 7493
[post_author] => 1
[post_date] => 2015-07-19 18:58:08
[post_date_gmt] => 2015-07-19 18:58:08
[post_content] =>
[post_title] => Forum
[post_excerpt] =>
[post_status] => publish
[comment_status] => open
[ping_status] => closed
[post_password] =>
[post_name] => forum
[to_ping] =>
[pinged] =>
[post_modified] => 2016-02-27 16:31:08
[post_modified_gmt] => 2016-02-27 16:31:08
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://xeepress.com/?p=7493
[menu_order] => 51
[post_type] => nav_menu_item
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
=> Following information as missing in here:
[db_id] => 7490
[menu_item_parent] => 7493
[object_id] => 7490
[object] => custom
[type] => custom
[type_label] => Custom Link
[title] => Single Forum
[url] =>
[target] =>
[attr_title] =>
[description] =>
[classes] => Array
(
[0] =>
)
[xfn] =>