unfulvio / wp-api-menus

:abcd: Menu routes for WordPress JSON REST API.
https://wordpress.org/plugins/wp-api-menus
GNU General Public License v2.0
140 stars 59 forks source link

Support for custom metas/ACF fields #47

Open lewisdonovan opened 7 years ago

lewisdonovan commented 7 years ago

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

lewisdonovan commented 7 years ago

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;
    }
}
dambrogia commented 7 years ago

Might want to check this out as well

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

isuke01 commented 6 years ago

@lewisdonovan Thanks you :)

Saggitarie commented 2 years ago

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.