Support

Account

Home Forums ACF PRO Using ACF Menu Items to create Sub Menu

Helping

Using ACF Menu Items to create Sub Menu

  • I’m trying to use the ACF Menu Items feature to create custom sub/dropdown menus, I’ve got it close to working, the issue is that my code is getting inserted within the , and I need it right after. I have a repeater within the Menu Items which is causing some complication.

    add_filter('wp_nav_menu_objects', 'my_wp_nav_menu_objects', 10, 2);
    function my_wp_nav_menu_objects( $items, $args ) {
    	foreach( $items as &$item ) {
    		$menuType = get_field('field_5ab26a060c9c7', $item);
    		
    		// Default Sub Menu
    		if( $menuType == "default" ) {
    			$subMenu = array();
    			while ( have_rows('field_5ab26a690c9c8', $item) ) : the_row(); 
    				$itemLabel = get_sub_field('field_5ab26a9b0c9c9', $item);
    				$itemLink = get_sub_field('field_5ab26aab0c9ca', $item);
    				$itemIcon = get_sub_field('field_5ab26ac60c9cb', $item); 
    
    				$subMenu[] = ' <li class="navigation__sub-menu-item"><a target="'.$itemLink["target"].'" href="'.$itemLink["url"].'">'.$itemLabel.'</a></li>';
    
    			endwhile; 
    			$item->title .= ' <ul class="navigation__sub-menu">'.implode(" ", $subMenu).'</ul>';
    			
    		}
    	}
    	// return
    	return $items;	
    }
  • After looking into it more, I think I’m going into this wrong. I should be using the native WordPress menu functionality to add submenu items, and ACF fields for icons/descriptions. Disregard original post.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Using ACF Menu Items to create Sub Menu’ is closed to new replies.