-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Adding user custom fields to the reponse #10
Comments
Hi @Pxlat, Yes, this solution works too. See below the example: add_filter( 'acf/rest_api/user/get_fields', function( $data, $request, $response ) {
if ( $response instanceof WP_REST_Response ) {
$data = $response->get_data();
}
if( isset( $data['acf'] ) ) {
$data['acf']['my_fields']->acf = get_fields( 1 ); // get fields from post #1
}
return $data;
}, 10, 3 ); Whats fields do you want to append in your response? |
I want to append the field "logo" from this endpoint http://s15695.p20.sites.pressdns.com/wp-json/wp/v2/users/ into this endpoint http://s15695.p20.sites.pressdns.com/wp-json/wp/v2/wimo-order/ in "acf.retailer" |
Hi @Pxlat, Please, replace the filter of isseu #9 by bellow code: add_filter( 'acf/rest_api/wimo-order/get_fields', function( $data, $request, $response ) {
if ( $response instanceof WP_REST_Response ) {
$data = $response->get_data();
}
if( isset( $data['acf'] ) ) {
$data['acf']['shipping_address']->acf = get_fields( $data['acf']['shipping_address']->ID );
// only logo
// $data['acf']['retailer']->logo = get_field( 'logo', 'user_' . $data['acf']['retailer']->ID );
// all acf fields
$data['acf']['retailer']->acf = get_fields( $data['acf']['retailer']->ID );
}
return $data;
}, 10, 3 ); |
Didn't work..do you think this has anything to do with Auth? http://s15695.p20.sites.pressdns.com/wp-json/wp/v2/users/5 |
In the plugin ( wp rest api ) has some conditions for you get data from users. |
Hi @Pxlat, |
Hi @Pxlat, please, check that the filter below will work: add_filter( 'acf/rest_api/item_permissions/get', function( $permission, $request, $type ) {
if ( 'user' == $type && method_exists( $request, 'get_param' ) && get_current_user_id() == $request->get_param( 'id' ) ) {
return true;
}
return $permission;
}, 10, 3 ); Thanks |
Hi, Thanks for your great code,
#9 Does this solution work also to get fields from /users/ ?
The text was updated successfully, but these errors were encountered: