Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for custom metas/ACF fields #47

Open
lewisdonovan opened this issue Aug 30, 2017 · 4 comments
Open

Support for custom metas/ACF fields #47

lewisdonovan opened this issue Aug 30, 2017 · 4 comments

Comments

@lewisdonovan
Copy link

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
Copy link
Author

lewisdonovan commented Aug 30, 2017

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
Copy link

Might want to check this out as well

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

@isuke01
Copy link

isuke01 commented Mar 1, 2018

@lewisdonovan Thanks you :)

@Saggitarie
Copy link

Saggitarie commented Nov 11, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants