Modify Relation Data
Data of a relation JSON request can be modified using WordPress' built-in filters, namely rest_{post_type}_query and rest_{taxonomy}_query. To distinguish WPCE requests from other REST API requests, the editor sends along the x-wpce-element-id and x-wpce-property-id headers.
So for example to modify a relation input with the ID posts in an element with the ID recent-posts to only show posts by the current user, the following code could be used:
php
add_filter('rest_post_query', function ($args, WP_REST_Request $request) {
if (
$request->get_header('x-wpce-element-id') === 'recent-posts' &&
$request->get_header('x-wpce-property-id') === 'posts'
) {
$args['author'] = get_current_user_id();
}
return $args;
}, 10, 2);