unfulvio/wp-api-menus

Support for custom metas/ACF fields

lewisdonovan opened this issue · 4 comments

Hi there,

Great plugin! Just wondering if there's any way I could add in support for displaying custom metas attached to a menu? Since 5.6.0, Advanced Custom Fields has added support for adding custom fields to menus, would be great to be able to pull this into the API.

If you're looking for contributors I'm happy to get involved on this. Cheers

Anyone using the v2 API and looking for a quick fix for ACF fields, you'll need to add the following edits to includes/wp-api-menus-v2.php

From line 159:

//get ACF fields
$fields = get_fields('term_'.$menu['term_id']);
//If we have fields...
if ($fields){
    //Loop through them...
    foreach ($fields as $field_name => $value){
        //Set the meta
        $rest_menu[$field_name] = $value;
    }
}

From line 116:

//get ACF fields
$fields = get_fields('term_'.$menu['term_id']);
//If we have fields...
if ($fields){
    //Loop through them...
    foreach ($fields as $field_name => $value){
        //Set the meta
        $rest_menus[ $i ][$field_name] = $value;
    }
}

Might want to check this out as well

https://github.com/airesvsg/acf-to-rest-api

@lewisdonovan Thanks you :)

Hi @lewisdonovan @dambrogia @isuke01 or any maintainer

Is this compatible with acf? I can't really see them from the endpoints?

Looked at the codes and saw the implementations for acf. But doesn't show in the response.

BTW, i have acf-to-rest-api installed.