Log1x / acf-composer

Compose ACF Fields, Blocks, Widgets, and Option Pages with ACF Builder on Sage 10.
https://github.com/Log1x/acf-composer
MIT License
423 stars 57 forks source link

Grabbing data from menu item #108

Closed minemindmedia closed 2 years ago

minemindmedia commented 2 years ago

Does anyone know how to grab the data from an ACF menu item and display it while using Navi? (https://github.com/Log1x/navi)

For example, I've successfully added a simple text input to each menu item:

<?php

namespace App\Fields;

use Log1x\AcfComposer\Field;
use StoutLogic\AcfBuilder\FieldsBuilder;

class Menus extends Field
{
    /**
     * The field group.
     *
     * @return array
     */
    public function fields()
    {
        $menus = new FieldsBuilder('menus');

        $menus
            ->setLocation('nav_menu_item', '==', 'all');

        $menus
            ->addText('subtext', [
                'label' => 'Sub-text'
            ]);

        return $menus->build();
    }
}
image

I am attempting to pull that input data to the menus under the menu title but can't quite determine how to do so.

The documentation from ACF for Displaying Fields requires setting up a function for wp_nav_menu_objects but that doesn't work using Brandon's Navi package.

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

Log1x commented 2 years ago

https://github.com/Log1x/navi#accessing-custom-fields this should work I think.

{{ get_field('subtext', $item->id) }}
minemindmedia commented 2 years ago

Thanks @Log1x - HUGE FAIL on my part. Not sure how I missed that!