HELP! dead-end Get post name or title related to nav_menu_item
-
My apologies if you entered here thinking menu’s custom clases would solve my dilema. Unfortunately they won’t.
I’d like NOT to depend on adding custom classes to menus because “better not to explain so we can move forward”, and I desperately need to format every icon different, using the page name, NOT the ID.
THE PROBLEM is nav_menu_items don’t have post-title nor post-name, AT LEAST they are different than the post/page they are associated with (sloppy way of prevent conflicts in DB, faster than filtering functions)
I found a function that adds my own class-name hooking into the function that constructs the menu_items list, but it processes nav_menu_items, not pages, which DON’T HAVE post-title or post-name, so I have to get the associated post ID somehow (I don’t like pure SQL queries)
// clears generated classes and adds (tries to) post_name to it function page_name_class( $css_class, $post ) { $css_class = array(); $css_class[] = 'pagename_' . sanitize_title_with_dashes( $post->post_title ); $css_class[] = 'menuorder-' . $post->menu_order; return $css_class; } add_filter( 'nav_menu_css_class', 'page_name_class', 10, 2 ); add_filter( 'page_css_class', 'page_name_class', 10, 2 );
So the question is:
How do I get the actual post-ID or better the post-title for that function when it loops through nav_menu_items which lack of post-id or page-title/name?
- The topic ‘HELP! dead-end Get post name or title related to nav_menu_item’ is closed to new replies.