I had to compare the $object_id
with the current queried object id instead of the post id. https://www.robbertvermeulen.com/wp_get_nav_menu_items-current-menu-item/
$object_id = get_post_meta( $id, '_menu_item_object_id', true );
$current = ( $object_id == get_queried_object_id() ) ? 'current-menu-item' : '';
Related Posts:
- Remove current_page_parent nav class from blog index when in CPT
- How to add meta box to backend menu page
- Why are navigation items saved in the database?
- adding .current* tags to custom post types and taxonomies
- Add/Remove current_page_parent class
- How can i change the output of posts_nav_link();
- Custom Post Types in the WordPress Navigation Menu
- How can i automatically add CPT single pages as sub menu items
- How can I use archive-{post_type}.php theme template?
- How to create a Child & Siblings menu for a custom post type?
- Navigation not working for custom post type pages
- wp_nav_menu doesn’t seem to work on custom post type pages
- Calling the first & last post by category in custom post type
- current_page_item and custom post type?
- Navigation won’t update to show full path to single post
- How to display custom WP menus?
- Custom post type archive page blank
- How do I check if the user is on a taxonomy term parent, child or grandchild page?
- How To Show All Custom Post Types In A Category Instead Of Pagination?
- Custom archive page for CPT UI
- How to display custom post in archive section of the wordpress page?
- The loop seems stuck to a single (now deleted) post
- Use “archive” as slug for custom post type
- Is there a way to establish parent/child relationship in WP menu links exclusively?
- Custom post type / taxonomy rewrite archive page 2 gives 404
- Use custom walker to add taxonomy terms to main nav menu
- Archive for CPT
- A page that shows a list of a specific custom post type
- Is it better to use filter for the_content in archive pages?
- Single custom post type’s menu ancestor/parent is Posts archive page
- Losing Nav Active State in Menu
- menu link to custom post_type?
- Review site custom post type structure
- How can I get this request to use the Custom Post Type page template instead?
- Custom post type posts don’t show in archive widget
- Archive for a Taxonomy of a Custom Post type
- Archive not sorting correctly
- Problems with 404, .htaccess, permalinks and WordPress custom posts locally on Snow Leopard
- Custom Post Type & Custom Menu Walker to append custom class for active post types
- Ordering Submenu Pages in WP 3.1
- Including link to custom post type in ‘wp_list_pages’ function
- What’s the name of the custom post type yearly archive template?
- how to remove pages loading with the archive templates
- Archieve.php not loading for custom post type
- multiple custom post type on category page
- Custom Post type & Taxonomy 404
- Which Template Page Should I Use?
- How does the ‘the_post_navigation()’ work for CPT’s?
- Custom Post Type Link added to menu won’t show in frontend
- Taxonomy archive 404ing (not term archive)
- Return the name of the post type
- How To Display A List Of CPT Posts In A Meta Box On Menus Page?
- Assign CPT archive page attributes
- Set a hard-coded page-template (post-type-archive) as home/front-page of my wordpress blog?
- Get custom post type categories to show up in menus
- How can I create an automatic drop down menu with my tags?
- show current item in custom menu, when inside a custom post type
- Custom taxonomy or custom page templates?
- Dynamically insert an article at the top of a taxonomy archive – or?
- Archiving custom post content?
- WordPress menu with custom taxonomy
- archive as a page, so that it can be added in the wp_menu_nav
- Displaying Custom Posts
- Prevent custom post type from showing up in custom menus
- Can anyone clarify difference between archive-{posttype}.php, type-{posttype} and date.php?
- How do I add custom HTML to the content of an archive page’s posts?
- Only show posts with a specific term of an associated taxonomy in a custom post type archive
- Archive links for custom post types
- Show All Custom Post Types On A Single Archive Page
- Use the custom post type archive for taxonomies?
- How to rewrite custom taxonomy term archive to use THE SAME SLUG/front as CPT
- List All Custom Post Types Posts in Nav Menu Dynamically
- Custom Post Type setup
- Archive Page for Multiple Custom Post Types
- Can’t access private custom posttype single- or archives-page
- Display Date & Author Info on Custom Post Type Archive Page
- How to constrain the results to a specific post_type on tag archive page?
- Custom Post Type – Portfolio no longer works
- Get the link of the first post of a custom taxonomy in a custom taxonomy list
- How can I relate custom post types?
- Current author archive in navigation menu
- Dynamic category name in query post
- Custom Post Type Archive Pagination
- How to programmatically add elements in a custom menu
- How to know which archive page is active
- Need to have an archive widget which organizes and displays a custom post type using a custom date field
- Archive page for custom post type and custom taxonomy
- Archive Template being used instead of Category Template for Custom Post Type
- Why does my URL keep returning 404 error code?
- pre_get_posts works in post type archive but not in single post
- Menu’s breaking, now showing all page links on site
- Display CPT index page as front/home page
- How to prevent a custom post type from using the archive.php template?
- New posts label category with “new”
- Custom Posttype and menu classes
- highlight parent page menu item when in custom post type
- Event Archive by Month
- How to have multiple archive pages?
- Create a Custom Path to Archive
- Advanced archive url structure (category, tag and date)