Last active
September 22, 2021 10:30
-
-
Save daggerhart/c17bdc51662be5a588c9 to your computer and use it in GitHub Desktop.
Author
Thanks for digging into that @webdados!
Those changes make great sense. I've updated this gist to reflect the changes. Very much appreciated!
You're welcome @daggerhart
I added "classes" support here: https://gist.github.com/webdados/d7a31f1363ef65d8a220e5ec87c1f1e8
Author
Moved to this repo. PRs welcome! https://github.com/daggerhart/wp-custom-menu-items
Nice!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When adding posts or taxonomy terms with
add_object, this notice will happen for the currently active menu item:Notice: Undefined property: stdClass::$post_parent in .../wp-includes/nav-menu-template.php on line 415To avoid this, we must add a
post_parentproperty to the$item_objobject on themake_item_objmethod.From the tests I've done adding both posts and taxonomy terms via the regular Appearance > Menus tool at wp-admin, I've come to the conclusion that
post_parentis the actualpost_parentfor posts and the termparentfor taxonomy terms.So this is what needs to be done:
At
add_object: Addpost_parentas$object->post_parentto the menu_item when$object_type == 'post'At
add_object: Add tt.parent to the SQL query atadd_objectwhen$object_type == 'term'At
add_object: Addpost_parentas$object->parentto the menu_item when$object_type == 'term'At
make_item_obj: Add$item_obj->post_parentas!empty( $item['post_parent'] ) ? $item['post_parent'] : ''You can find the full class with the changes at https://gist.github.com/webdados/e069ce33947a0e981aede33c79a4d837