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
- Adding a Custom Post Type into the menu screen
- Highlighting wp_nav_menu() Ancestor Class w/o Children in Nav Structure?
- Permalink Structure for Multiple Post Type Archives by Taxonomy
- Displaying category archive of custom post types
- Meta_Query as a way how to setup CPT permalinks – is it a good thing?
- How to order adjacent posts (prev / next) by custom field value?
- Setting up custom post type archives in WP3.1? Any luck?
- Filter for “get_post_type_archive_link()”
- How to show more posts on an archive page?
- Create permalink structure for one taxonomy archive per custom post type
- wp_list_pages not showing cpt as I expected
- Renaming Menu Item within Admin Menu Section for a Custom Post Type?
- Better to use a post type archive, page template, or shortcode for generating a highly configurable CPT archive?
- Problem excluding category from get_next_post
- Display all custom post types in archives.php
- Custom Post Type Archives by Date (stored as meta value) WP3.1
- Custom post type tag archives don’t work for basic loop?
- Multiple post types in archives (filter?)
- How to let custom post type posts show in standard post archive (like in homepage)?
- Nav menu of all posts in a custom post type
- Highlight nav menu terms
- Disable single pages and archives and keep preview
- Custom post type archive sorted and grouped by date in post meta field
- Which User Role for Custom Post Type Menu – wp_nav
- Custom post type with tags
- List custom post type but redirects to home page
- Settings page above CPT page in admin section
- Remove current_page_parent from posts page link in WordPress nav menu
- Custom-post-type-archive: posts sorted/filtered by year?
- Custom post type archive page pagination
- Add the current menu item CSS class to a custom page type archive in WordPress menu
- How to change the admin menu “Pages” to something else
- Need post_type_archive_title function but in ‘single’
- Navigation menus not showing because of custom post type filter
- Hierarchical Custom Post Types – Show only parent on tax archive?
- Custom post types archive redirect
- just can’t get date-based archives per post-type to work
- Set menu active state for custom posttype and category, given custom taxonomy term
- Archive page for taxonomy terms
- Function to display custom post type on front page makes menu items dissapear
- How to make this menu drop down or like accordion
- Custom Post Type with archive page but no detail page
- Using default WP menu functionality to link to custom post-type listing?
- wordpress wp_list_pages help
- How to get post type and month/year before while loop for date.php file
- How to display custom WP menus?
- Custom archive page for CPT UI
- How to display custom post in archive section of the wordpress page?
- Is there a way to establish parent/child relationship in WP menu links exclusively?
- Archive for CPT
- A page that shows a list of a specific custom post type
- Including link to custom post type in ‘wp_list_pages’ function
- Custom Post type & Taxonomy 404
- How does the ‘the_post_navigation()’ work for CPT’s?
- Set a hard-coded page-template (post-type-archive) as home/front-page of my wordpress blog?
- WordPress menu with custom taxonomy
- Archive links for custom post types
- Archive Page for Multiple Custom Post Types
- How to know which archive page is active
- Archive page for custom post type and custom taxonomy
- highlight parent page menu item when in custom post type
- How to have multiple archive pages?
- Create a Custom Path to Archive
- Advanced archive url structure (category, tag and date)
- Custom post type post in custom menu
- Listing authors and date archive from custom post type
- WordPress sitemap with Custom Post Types
- How to show custom post count in archive page
- Do not show child pages within a file page
- Archive for custom taxonomy
- Adding Custom Post Types to category/tag/author archives breaks header content
- Possition a Custom Post Type Tab under Settings
- Want to display my custom date archive to date.php but dont know how
- How can I generate a list of post-type specific categories?
- Stop Custom post type from being searched via URL
- List all posts from custom post type by taxonomy
- archive-{custom_post_type}.php not getting recognized wordpress
- how to override menu widget?
- ‘Blog Archive’ suddenly appeared on custom post type; how to remove
- Display results from two Custom Post Types in page template
- Stop header code from showing in category page?
- Show posts of parent in edit.php
- Highlight specific menu item when custom post is page
- sidebar hierarchical menu category & custom post type
- get_the_post_navigation not working