It is a bit more complicated to achieve. It needs too filters :
- one to allow the new REST parameter
- another to set the WP_Query argument
add_filter( 'rest_post_collection_params', 'collection_params', null, 2 );
add_filter( 'rest_post_query', 'query', null, 2 );
function collection_params( array $query_params, \WP_Post_Type $post_type ): array {
$query_params['post__not_in'] = [
'description' => 'Excludes posts.',
'type' => 'array',
'default' => [],
];
return $query_params;
}
function query( $args, \WP_REST_Request $request ) {
if ( isset( $request['post__not_in'] ) && count( $request['post__not_in'] ) ) {
$args ['post__not_in'] = $request['post__not_in'];
}
return $args;
}
Related Posts:
- Get post count in wp rest API v2 and get all categories
- Are there server performance benefits to fetching only specific fields when querying the REST API?
- WordPress Rest API: How do we validate with our custom API key?
- Hiding API routes list
- Can we access the REST request parameters from within the permission_callback to enforce a 401 by returning false?
- WordPress REST API “rest_authentication_errors” doesn’t work external queries?
- How to filter users on custom meta fields in WP JSON v2?
- Gutenberg Custom Block Getting All Posts
- Display post title from WordPress excluding a string via API
- WP_REMOTE_POST Requests are being blocked by API provider [closed]
- is it possible to filter a rest api endpoint by using a registered rest field?
- Use the backbone.js client to save custom post type meta
- No ‘Access-Control-Allow-Origin’ when call rest API
- Update a post based on results from GET request to another server
- Get a remote post ID via API given URL
- Core function to check if a rest namespace exists
- How to change the date and time in REST API for comments?
- Is there a way to download only the Rest API part of WordPress?
- WordPress REST Api get posts by ID
- How to use Python to create a Post in WordPress?
- Cannot use WordPress Application Passwords: “code”: “rest_no_route” “status”:404 for /wp-json/wp/v2/users/me/application-passwords
- How to display relations via wordpress Rest API
- register/login api
- WordPress REST API in Integromat: How to overcome “Sorry, you are not allowed to list users / edit this…”
- Remove unwanted fields from WP API response
- WordPress API “code”:”rest_no_route” with Custom Route
- API request forbidden when requesting from same domain
- Woocommerce API for calling products by Category ID
- wordpress rest api authentication failed
- Is the WordPress REST API installed and enabled in a vanilla WordPress 4.7 installation?
- Hiding WordPress REST API v2 endpoints from public viewing
- check the requesting url
- WP REST API Require Password for GET Endpoint
- WP REST API V2 – Retrieve sub page by full slug (URL/Path)
- How to loop through JSON data in wordpress WP REST API
- WP REST API V2 – Modifying responses
- How to use the WP REST API for new user registration (sign up form)?
- Can I authenticate with both WooCommerce consumer key and JWT?
- WP REST API: check if user is logged in
- wordpress custom endpoint multiple params
- Adding post fields in wp-json/wp/v2/search
- Unable to get the info of the user which doesn’t have created any post via REST API
- WordPress Gutenberg get page template value when post updated?
- Can’t GET draft posts via REST API from headless frontend
- How to update custom meta fields with rest api?
- Rest API and Custom Fields
- WordPress REST API, Expired Nonce from Cache results in 403 forbidden
- WP Rest API: Get User by Email
- How to retrieve custom meta term of category taxonomy from WP Rest API?
- Can we assume that /wp-json/ will always be /wp-json/ under any circumstances when creating custom REST routes?
- Passing a borrowed nonce through Postman fails
- How to add WP API and JS featured image attachment
- How to hook into “register_rest_field” to modify the behavior of a custom field?
- Get all PDF files from page with WordPress API
- current_user_can(‘administrator’) returns false when I’m logged in
- How to add / embed an author into REST data from a custom post type?
- How to enable the view of revisions of post in WordPress Api for custom post type?
- Problem on creating custom endpoints for REST
- New user signup via REST API
- Ho to style post content for WordPress API?
- WP REST API can’t set post tags
- rest_no_route on custom API endpoint wordpress
- WP_REST_Response() doesn’t seem to return the expected object
- Setting ?context=edit results in rest_forbidden_context, even for an Administrator user
- WP Rest Api- Update callback (POST request) to existing database table through the rest api
- Save default options as an array of options and display in REST API
- [Zapier + WP Webhooks Pro]: Custom Fields get cut off at first comma or semicolon
- Which route in the WP REST API do I access data passed into register_setting()?
- update_callback is not working in register_rest_field
- Send a get request to wordpress
- Best Authetication between REST API and Mobile App
- Replace content via rest api only?
- How to make an API call to a custom post type but filtering by meta value?
- WP rest api endpoint protection using jwt token
- WP Rest API – Change response status code for failed validation request
- Unable to create a Rest end-point
- Log in user using WordPress REST API
- Check if user can in javascript
- WordPress Rest Api rest_cannot_edit
- how to create JSON array [] for REST response?
- Getting 401 unauthenticated error in WP Rest API revisions
- How to receive JSON payload from a digital device
- WordPress Custom Rest Api – How to get Image Url?
- Adding Amchart Interface to WordPress API
- Remote publishing using WP’s RetAPI // Issues with HTACCESS
- save_post hook error with REST API
- Connecting WordPress with an External API
- Deleting media using the WordPress Rest API
- Users REST API not working?
- Using WordPress solely as a Backend – dealing with WP_SITEURL
- use WordPress Rest API to build a web application
- REST Request Post including meta/custom fields
- Why wp_set_password not working within a api endpoint?
- WordPress api returns distinct data
- Redefine REST API variables
- WP-API + JS Backbone client – how to update post meta
- Where is the HTML content for my post in the API
- WordPress Rest API Escapes Returned URLs Forward Slash
- Script tag in string in wordpress rest api body to create post
- Customizer Changeset, Sidebar and Rest API Custom Endpoints