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 JSON #41

Closed
anomaddev opened this issue May 29, 2016 · 4 comments
Closed

Rename from 'acf' in JSON #41

anomaddev opened this issue May 29, 2016 · 4 comments

Comments

@anomaddev
Copy link

Is there a way to edit how the acf fields show in the JSON listing? For example I do not want my custom field to show under the field 'acf' but something custom. With the old plugin I was able to find how to change this but with V2 I am unable to find where this is set.

@airesvsg
Copy link
Owner

Hi @justinackermann,
you should use the filter "acf/rest_api/{type}/get_fields".

The wildcard {type} can be: post, page, user, term, comment, attachment, options or custom_post_type ( book )...

Thanks

add_filter( 'acf/rest_api/{type}/get_fields', function( $data ) {
    if ( method_exists( $data, 'get_data' ) ) {
        $data = $data->get_data();
    } else {
        $data = (array) $data;
    }

    if ( isset( $data['acf'] ) ) {
        $data['key'] = $data['acf'];
        unset( $data['acf'] );
    }

    return $data;
} );

@anomaddev
Copy link
Author

anomaddev commented May 30, 2016

I think you misunderstood me or I am misunderstanding you. Currently my json is for example:
acf: { field_title: "data" }

I would like it to be something like:
custom_naming_scheme: { field_title: "data" }

For mapping purposes on external sources I do not want to use the 'acf' naming.

@airesvsg
Copy link
Owner

add_filter( 'acf/rest_api/{type}/get_fields', function( $data ) {
    if ( method_exists( $data, 'get_data' ) ) {
        $data = $data->get_data();
    } else {
        $data = (array) $data;
    }

    if ( isset( $data['acf'] ) ) {
        $data['custom_naming_scheme'] = $data['acf'];
        unset( $data['acf'] );
    }

    return $data;
} );

@misfist
Copy link

misfist commented Jun 28, 2016

Thanks! This is just what I was looking for!

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

3 participants