2

For the search endpoint, the object type (the first parameter for register_rest_field()) is search-result and not the post type (e.g. post, page, etc.). So try with this, which worked for me: add_action( 'rest_api_init', function () { // Registers a REST field for the /wp/v2/search endpoint. register_rest_field( 'search-result', 'excerpt', array( ...


2

pre_delete_post hook filters whether a post deletion should take place. So callback function must return a boolean value: true - whether to go forward with deletion, false - if not. pre_trash_post hook filters whether a post trashing should take place. So callback function must return a boolean value: true - whether to go forward with trashing, false - if ...


1

The error in question — "Invalid parameter(s): tags" and "tags[0] is not of type integer.", means that you need to supply a list of tag IDs and not names or slugs. So for examples, 'tags' => 123 and 'tags' => [ 123 ] are both valid. (Comma-separated list is also accepted, e.g. 'tags' => '123,4,5'.) And all that also apply to the ...


1

First you need to tell WordPress to show this custom field in the API response: register_term_meta('category', '_category_color', ['show_in_rest' => true]); Then you can filter the category term API endpoint like so: add_filter( 'rest_prepare_category',function($response, $item, $request){ $color = get_term_meta( $item->term_id, '_category_color', ...


1

When doing a direct WP_REST_Request, the syntax is not the same as when interacting with the REST API through its HTTP interface. So Kaperto's response was correct. Because WP_REST_Request accepts three arguments: The method. The route. The arguments. If you add the arguments to the route, it will not be recognized by the REST API. This is a passing test: ...


1

I think I found answer to your question, it is: rest_{$this->post_type}_query filter hook. With this hook you are able to directly edit internal WP_Query parameter. For example, if you'd like to internally sort Posts by post_title by default, then you'd have to write something like this: function order_rest_post_by_post_title($args, $request) { $args['...


Only top voted, non community-wiki answers of a minimum length are eligible