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

Rename from 'acf' in response #11

Closed
misfist opened this issue Jul 3, 2016 · 2 comments
Closed

Rename from 'acf' in response #11

misfist opened this issue Jul 3, 2016 · 2 comments

Comments

@misfist
Copy link

misfist commented Jul 3, 2016

I temporary need to use v1 of the REST API and would like to change acf to something else (say, custom_fields). Your explanation for v2 (airesvsg/acf-to-rest-api#41) worked exactly as expected. So, I tried to do something similar in v1 using the acf_to_wp_rest_api_{$this->type}_data filter.

But, I wasn't able to get it to work.

apply_filters( "acf_to_wp_rest_api_{$this->type}_data", $data, $object, $context );

Any guidance would be appreciated.

@airesvsg
Copy link
Owner

airesvsg commented Jul 3, 2016

Hi @misfist,
please try it:

add_filter( 'acf_to_wp_rest_api_{type}_data', function( $data ) {
    if ( isset( $data['acf'] ) ) {
      $data['custom_fields'] = $data['acf'];
      unset( $data['acf'] );
    }

    return $data;
}, 10 );

The wildcard {type} can be: post | user | term | comment | attachment | options

Thanks

@misfist
Copy link
Author

misfist commented Jul 3, 2016

Thank you! I really appreciate you getting back to me! It worked exactly has I wanted.

@airesvsg airesvsg closed this as completed Jul 4, 2016
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

2 participants