Support

Account

Home Forums Backend Issues (wp-admin) i cant use get field in walker

Helping

i cant use get field in walker

  • in first sorry for my weak English

    i try to change my sub menu style with walker like this :

    class sublevel_wrapper extends Walker_Nav_Menu {
            function start_lvl( &$output, $depth = 0, $args = array() ) {
                $indent = ( $depth > 0  ? str_repeat( "\t", $depth ) : '' );
                $display_depth = ( $depth + 1);
                $classes = array(
                    'sub-menu',
                    'menu-depth-' . $display_depth
                );
                $class_names = implode( ' ', $classes );
                if ($display_depth == 1) {
                    $output .= "\n" . $indent . '<div class="object"><div class="submenu"><div class="icon">'. get_field('icon', $item) .'</div><ul class="' . $class_names . '">' . "\n";
                } else {
                    $output .= "\n" . $indent . '<ul class="' . $class_names . '">' . "\n";
                }
            }
        }
    

    in this code i want to use font awesome icon in acf nav items with field name : icon
    but this code isnt working , please correct my code.

  • Are the fields added on the page or on the nav menu item itself ( Via Appearance -> Menus )?

    Have you tried get_field( $item->ID )?

    Additionally, the walker method should look like this:

    function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {

    Your current method is missing $item entirely. It may be helpful to turn on PHP Debugging.

    https://developer.wordpress.org/reference/classes/walker_nav_menu/

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

The topic ‘i cant use get field in walker’ is closed to new replies.