Sorting custom taxonomy causes menus error

Currently your code is modifying all term queries, both in the front-end and in the back-end.

Each navigational menu is registered as a term in the nav_menu taxonomy, so when you visit the backend to work on the menus, those queries have been modified too by your code snippet.

For example, I don’t see any ! is_admin() check in your code.

You should target only the relevant term query, e.g. adding the filter just before the term query and then remove it right again afterwards. Another approach would be to use a custom input argument to activate the filter.

ps: Even though each navigational menu is registered as a term under nav_menu, each menu item is a nav_menu_item custom post type and the tree structure is stored in the post meta table under the _menu_item_menu_item_parent meta key for each post. I just wanted to mention this, as it might be understood from what I wrote here above that the menu is only part of the taxonomy structure.

Leave a Comment