We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hey,
I were able to implement a modified REST response by using:
add_filter( 'acf/rest_api/fishes/get_fields', function( $data ) { if ( method_exists( $data, 'get_data' ) ) { $data = $data->get_data(); } else { $data = (array) $data; } if ( isset( $data['acf'] ) && ! $data['acf'] ) { $data['acf'] = array(); } add_custom_fields_to_response ($data); // I pass $data by reference return $data; } );
When I call wp-json/acf/v3/fishes/291 I got my custom field added to the default fields. That's fine.
wp-json/acf/v3/fishes/291
But I'm missing these custom fields when calling all fishes by wp-json/acf/v3/fishes.
fishes
wp-json/acf/v3/fishes
I created a custom REST route:
add_action( 'rest_api_init', 'register_custom_routes', 10 ); function register_custom_routes() { register_rest_route( 'acf/v3', '/fishes', array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => 'get_fishes', 'args' => array ( 'custom_post_type' => 'fishes' ) ) ) ); } function get_fishes(WP_REST_Request $request) { $filter = $request->get_param( 'filter' ); $data = array(); $args = array( 'posts_per_page' => -1, 'post_type' => 'fishes', ); if ( is_array( $filter ) && array_key_exists( 'category', $filter ) ) { $args['category_name'] = $filter['category']; } $posts = get_posts( $args ); if ( ! empty( $posts ) ) { foreach( $posts as $post ) { $acf = get_fields( $post->ID ); if ( ! empty( $acf ) ) { $data[] = array_merge( array( 'id' => $post->ID ), $acf ); } } } return $data; }
Did I miss something? Please could someone shed some light on this?
Best, huppys
The text was updated successfully, but these errors were encountered:
Hi @Huppys, Please, read this issue #109 Thanks.
Sorry, something went wrong.
No branches or pull requests
Hey,
I were able to implement a modified REST response by using:
When I call
wp-json/acf/v3/fishes/291
I got my custom field added to the default fields. That's fine.But I'm missing these custom fields when calling all
fishes
bywp-json/acf/v3/fishes
.I created a custom REST route:
Did I miss something? Please could someone shed some light on this?
Best,
huppys
The text was updated successfully, but these errors were encountered: