Support

Account

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

  • I think you may be something else incorrect, but I can’t tell what it is from what you’ve provided.

    When using this

    
    add_filter('wp_nav_menu_items', 'my_wp_nav_menu_items', 10, 2);
    
    function my_wp_nav_menu_items( $items, $args ) {
    
    ...
    

    $args->menu should be a term object. When I add this filter and do print_r($args) I get this:

    
    stdClass Object
    (
      [menu] => WP_Term Object
        (
          [term_id] => 30
          [name] => manue 1
          [slug] => manue-1
          [term_group] => 0
          [term_taxonomy_id] => 30
          [taxonomy] => nav_menu
          [description] => 
          [parent] => 0
          [count] => 7
          [filter] => raw
        )
    
      [container] => div
      [container_class] => 
      [container_id] => 
      [menu_class] => nav-menu
      [menu_id] => primary-menu
      [echo] => 1
      [fallback_cb] => wp_page_menu
      [before] => 
      [after] => 
      [link_before] => 
      [link_after] => 
      [items_wrap] => <ul id="%1$s" class="%2$s">%3$s</ul>
      [item_spacing] => preserve
      [depth] => 0
      [walker] => 
      [theme_location] => primary
    )
    

    Looking at this https://www.advancedcustomfields.com/resources/adding-fields-menu-items/

    
    add_filter('wp_nav_menu_objects', 'my_wp_nav_menu_objects', 10, 2);
    
    function my_wp_nav_menu_objects( $items, $args ) {
    
    ...
    

    $args results in the same.

    Probably a little known fact, but $post_id when calling ACF functions can also be an object of type post, term or user.