I need to add a meta box to the backend menu page, in Appearance->Menus (/wp-admin/nav-menus.php
), to list all the available post types, both the defaults & the custom ones.
It will contain a list that contains a link to the archive pages only of the respective post types to be added to the nav menu. Is this possible?
Here is an example metabox that displays at the very top of the left hand side in the nav menus interface:
The important part of add_meta_box is:
There is a nav-menu post type, but it does not support metaboxes, and nav-menus.php is hardcoded to use the ‘nav-menus’ and ‘side’ values. As long as you respect this you can do anything else you please within reason.
Unfortunately adding extra fields to individual menu items themselves e.g. links, pages, etc, is not possible at the time of writing this as those fields are hardcoded. You could add them via jQuery, and then save them via hooks in the backend if you needed them.
As the meta box was already answered by @TomJNowell I only show you how to get the post type list:
It’s not tested, but it should work.
An alternate to @kaiser’s solution is the
get_post_types()
function. It should allow you a bit finer control over the post types.