Support

Account

Home Forums General Issues get_field for a menu fails Reply To: get_field for a menu fails

  • Okay,

    I played around some more, and this seems to be a bug/inconsistency related to the ambiguous ways you can call wp_nav_menu, in particular the menu attribute you can pass in, which can be:

    (int|string|WP_Term) Desired menu. Accepts (matching in order) id, slug, name, menu object.

    Here the different output for different ways of calling my menu:
    wp_nav_menu(array('menu' => 'Footer menu'));
    results in print_r($args->menu):

    stdClass Object ( [menu] => Footer menu [container] => div [container_class] => [container_id] => [menu_class] => menu [menu_id] => [echo] => 1 [fallback_cb] => wp_page_menu [before] => [after] => [link_before] => [link_after] => [items_wrap] =>
    %3$s
    [item_spacing] => preserve [depth] => 0 [walker] => [theme_location] => )

    Where as this:
    wp_nav_menu(array('menu' => 1));
    results in print_r($args->menu):

    stdClass Object ( [menu] => WP_Term Object ( [term_id] => 3 [name] => Footer menu [slug] => footer-menu [term_group] => 0 [term_taxonomy_id] => 3 [taxonomy] => nav_menu [description] => [parent] => 0 [count] => 1 [filter] => raw ) [container] => div [container_class] => [container_id] => [menu_class] => menu [menu_id] => [echo] => 1 [fallback_cb] => wp_page_menu [before] => [after] => [link_before] => [link_after] => [items_wrap] =>
    %3$s
    [item_spacing] => preserve [depth] => 0 [walker] => [theme_location] => ) MENUWP_Term Object ( [term_id] => 3 [name] => Footer menu [slug] => footer-menu [term_group] => 0 [term_taxonomy_id] => 3 [taxonomy] => nav_menu [description] => [parent] => 0 [count] => 1 [filter] => raw )

    So apparently the menu will render with both methods, but the $args->menu differs significantly, and in the string parameter variant does not result in the term object ACF is expecting. Hurray WordPress.