After searching through the core WordPress files, I found the necessary arguments. The key is setting menu-item-object
to be the slug of your post type and the menu-item-type
to be post_type_archive
.
$args = [
'menu-item-position' => $position,
'menu-item-status' => 'publish',
'menu-item-parent-id' => 0,
'menu-item-object' => 'my-post-type',
'menu-item-type' => 'post_type_archive'
];
wp_update_nav_menu_item($menuID, 0, $args);
Related Posts:
- is_page() not working with archives?
- Add custom page link with anchor
- How to use a WordPress’ existing admin icon?
- Menu Disappears on Category Pages
- Hiding Admin Page While Keeping Menu Expanded
- How to add custom menu item on plugin activation?
- Wp menu add page link as custom empty link
- add_submenu_page function to show videos table
- Check if Page Already Exists in Menu
- How can I use archive-{post_type}.php theme template?
- wp_get_archives doesn’t take effect from css or html
- add page to main menu (frontend)
- Adding archive years to my menu
- Current author archive in navigation menu
- How to link current logged-in user to their author page via URL (Beginner)
- Multisite Setup – Menu Items To Reference Pages in Different Subdomains
- How do I create a new directory to hold the assets for a new menu item?
- how to create pages and link them to a menu
- The menu item is not deleted on WordPress
- Footer navigation menu
- Custom search filter causes menu and query_posts problems
- Add separator to admin submenu
- register_nav_menus() won’t register menus
- How do I add nested categories to drop-down menu in twenty-eleven?
- How to include the ‘current-menu-ancestor’ class on a custom post type menu in WordPress?
- Show top-level parent with submenu menu walker
- Add section to custom menu panel
- Adding a class (arrows) to main menu links that have children?
- Output yearly archive within a page
- How to change menu according to the language?
- Custom post type archive sorted and grouped by date in post meta field
- Settings page above CPT page in admin section
- Highlight the “Home” / “Blog” button while on main page
- Navigation (wp_nav_menu) refuses to nest within parent element
- how to add Custom menu item like User name in Header Menu only
- Display three different levels of navigation from wp_nav_menu separately?
- Wp_Nav_Menu – Identify the last menu item
- Add custom menu item metabox in Navigation Settings
- Menus – Open items in new tab/window?
- Image as a link using wp_nav_menu()
- Highlight another nav item
- Get category ID from nav menu
- How to make link to different categories that in them selves loads different menus?
- Programmatically add existing pages and subpages to Appearance Menu
- Highlight current post ancestor parent menu items
- Ad custom admin page like WordPress customizer [closed]
- How to display custom post in archive section of the wordpress page?
- Appearance Menus Screen – menu item drop down menu not functioning
- Weird behaviour on Edit Menus screen
- Remove nav menu item by script
- Custom Menu Broken WP 3.8.1 Update
- How to actually make menu walker alive on admin interface?
- Get menus created with menu editor?
- How to I know the class or ID of my theme?
- Highlight parent if item from submenu is active
- How to exclude pages in the menu without pageID?
- Missunderstanding of WordPress menus
- How to add schema.org SiteNavigationElement and property URL to navbar?
- changing host.. data loss
- Theme Location empty
- Replace the slug of parent pages with # [closed]
- How to buid wordpress menu with auto width sub-menu items in dropdown menu without any items sharing one line [closed]
- Page appears after de registering from menu
- functions.php adding item to end of menu. I want to change position
- Custom Menu Anchor Links Not Working
- WordPress Menu Exchange for Mobile Layout
- Switching to child theme breaks menu names
- Custom archive pages without “the loop”
- Bootstrap menu – make menu entries with submenu not clickable
- How to implement a secondary menu?
- Styling issue with custom menus and sub menus
- When I click a custom menu link, how do I make it update the URL in the browser to the external link?
- Disabling tooltip on menu items
- Divide Menu into Separate Menus and Display them Side by Side
- Hook or callback when wp_nav_menu() has completed
- if role is logged in then do something
- Set one or more menus as a submenus of another menu
- How to show submenu of any page in main menu
- How to change the navigation menu
- Menu links URL with PHP GET method
- WordPress nav_menu items from another menu appearing
- Adding widget to sidebar which contains current page’s submenu
- How to switch menu location in this header.php?
- Extending Walker_Nav_Menu in wp_nav_menu List of Empty Items
- Jump to section on another page from menu item
- In Product Category archives how to show Posts having same/similar prod_cat slug structure?
- Users are required to login to my site. How define user.member boolean, its permissions, and conditionally display/handle behavior based on it
- How to Use Default Auto-Generated Menu?
- How to sort a sub-menu, generated with get_pages(), by the page order instead of alphabetically?
- Two questions about CSSing inside the menus
- Different menu on different category need advice
- Is there any way to recover deleted menu from database sql backup
- Add tooltips with image in WordPress Menu?
- How to make a drop down menu with categories
- How to use my custom menus as seperate pages?
- WordPress wp get nav menu items does not deliver external link
- wp_nav_menu changed to wp_page_menu
- how to assign an ID to a wordpress menu
- Site pages show the page title under navigation bar
- Keeping my Sub Menu open when hovering on its list items