Is it possible to get only the 1st three items in wordpress menu?
for example I have these menus.
HOME ABOUT PROPERTY SEARCH CONCIERGE CONTACT
and I want to get ony the first 3 menus.
your help is much appreciated.
Is it possible to get only the 1st three items in wordpress menu?
for example I have these menus.
HOME ABOUT PROPERTY SEARCH CONCIERGE CONTACT
and I want to get ony the first 3 menus.
your help is much appreciated.
I dont think there is any argument for that but this can be done like this:
$menu_name = 'custom_menu_slug'; // Get the nav menu based on $menu_name (same as 'theme_location' or 'menu' arg to wp_nav_menu)
if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) {
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
$menu_items = wp_get_nav_menu_items($menu->term_id);
$count = 0;
foreach ( (array) $menu_items as $key => $menu_item ) {
$count++;
if($count == 3 ) {
break;
}
$title = $menu_item->title;
}
}