-
-
Notifications
You must be signed in to change notification settings - Fork 113
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
Relation add acf fields? #223
Comments
I'm no longer on the specific project where we used this plugin so can't really help here to tell how we implemented our case. I remember that we have changed how we use the API back then so we no longer had this requirement. My PR was not implemented since I couldn't get it running with the Pro v5. I tried following-up but since priority and consumption changed I couldn't finish this. |
Hi @dmnsgn, I didn't the implementation, but you can use that solution: #109 (comment) Thanks |
Thanks for the pointers. Since I am using the <?php
$post_types = array_merge(get_post_types(), cptui_get_post_type_slugs());
foreach ($post_types as $type) {
add_filter(
'acf/rest_api/' . $type . '/get_fields',
function ($data, $response) use ($post_types) {
if ($response instanceof WP_REST_Response) {
$data = $response->get_data();
}
array_walk_recursive($data, 'get_fields_recursive', $post_types);
return $data;
},
10,
3
);
}
function get_fields_recursive($item)
{
if (is_object($item)) {
$item->acf = array();
if ($fields = get_fields($item)) {
$item->acf = $fields;
array_walk_recursive($item->acf, 'get_fields_recursive');
}
}
} @cannap that should work for you. |
Hi @dmnsgn, Please, test it: Thanks |
thanks all it works! now i can save some duplicated content and time :D |
@airesvsg I can't manage to make it work with the recursive plugin but it might be because my Custom Post Type are handled via the CPTUI plugin and you need to use this function to retrieve them: cptui_get_post_type_slugs() |
Hi @dmnsgn, Please, try it: add_filter( 'acf/rest_api/recursive/types', function( $types ) {
$slugs = (array) cptui_get_post_type_slugs();
$types += array_combine( $slugs, $slugs );
return $types;
} ); Thanks |
Yep, that works fine! |
Worked for me too! |
Hi guys, how are you guys not getting a response like this? "acf": { |
See the nested object? how to i stop that |
How do you prevent this from turning into a infinity loop? For example if one of the relation posts are the same as the parent post. |
hi as example
i have a
relation to a custom post type
now i need some acf fields in the relations output i got via acf but i dont know how :/
i use //xxxx.com/wp-json/wp/v2/pages?slug=arbeiten
The text was updated successfully, but these errors were encountered: