Define the callback as a named function and hook it separately for each post type.
function wpse_299908_order_rest_query( $args ) {
$args['orderby'] = 'menu_order';
$args['order'] = 'ASC';
return $args;
}
add_filter( 'rest_post_query', 'wpse_299908_order_rest_query' );
add_filter( 'rest_page_query', 'wpse_299908_order_rest_query' );
There’s no filter that automatically applies to all endpoints, likely for the same reason that you can’t query multiple post types at once to begin with. As discussed during development of the API:
Because each custom post type is modeled differently, it’s not
possible to fetch them from the same endpoint in v2. Conceptually,
it’s like fetching users and posts from the same end point — it
doesn’t make much sense.
Related Posts:
- Is the WordPress REST API installed and enabled in a vanilla WordPress 4.7 installation?
- Does something like is_rest() exist
- How to: Make JWT-authenticated requests to the WordPress API
- REST API purpose?
- Get post count in wp rest API v2 and get all categories
- WP REST API — How to change HTTP Response status code?
- wp_get_current_user() function not working in Rest API callback function
- How to use WP-REST API to login user and get user data for Android app?
- WP REST API Is it rather easy to rename the default wp-json uri part?
- Search WP API using the post title
- check the requesting url
- How would I add custom tables/endpoints to the WP REST API?
- WP REST API Require Password for GET Endpoint
- Displaying a page built with Elementor using the REST API [closed]
- Getting user meta data from WP REST API
- Understanding SHORTINIT with WordPress 5
- How to use _embed when using _fields?
- WP REST API V2 – Retrieve sub page by full slug (URL/Path)
- WP REST API create post authentication issue
- Why is my custom API endpoint not working?
- WordPress REST API validation
- Are there server performance benefits to fetching only specific fields when querying the REST API?
- How to define a query parameter with REST API?
- Filter posts by multiple custom taxonomy terms using AND operator in REST API v2 (WordPress)
- WP REST API returns blank response if post is too long
- How do I correctly setup an AJAX nonce for WordPress REST API?
- Increase per_page limit in REST API
- WordPress Rest API: How do we validate with our custom API key?
- Does pre_get_posts affect REST API responses?
- How to feed a HTML5’s EventSource with a REST API custom endpoint?
- Adding WordPress API Endpoint With Multiple Parameters
- Retrieve CSS and JS From the REST API
- Using the REST API (v2) javascript client on a private namespaced route
- How to Authenticate WP REST API with JWT Authentication using Fetch API
- authentication issue with rest api – rest_cannot_create
- WP REST API core major changes
- WordPress 4.7 REST API endpoints
- How to get all posts from parent and children categories?
- wordpress wp-json prefix issue
- Hiding API routes list
- Get blog title with REST v2
- Is it possible to nest the JSON result of WordPress REST API?
- Match REST API post output from custom endpoint
- How to use the WP REST API for new user registration (sign up form)?
- Can I authenticate with both WooCommerce consumer key and JWT?
- REST API multiple media upload
- Filter post_content before loading in Gutenberg editor
- Attach featured image to custom endpoints
- Can’t send emails through REST API
- 401 Error when trying to make a REST API call to site
- WordPress: How to create custom REST API route?
- Create post using rest api with html content
- Does jQuery/Ajax send cookies when using the rest API or do I need to somehow add them?
- WP REST API: check if user is logged in
- How to change user avatar using REST API?
- How to login to WordPress site using basic authentication HTTP headers?
- REST API URL parameters not working with apache server
- Adding post fields in wp-json/wp/v2/search
- Can we access the REST request parameters from within the permission_callback to enforce a 401 by returning false?
- How to Pull ALL Posts, Categories, or Tags in WordPress REST API
- rest api authentication
- Unable to get the info of the user which doesn’t have created any post via REST API
- Trying to get an api request getting error 404
- Upload image to wordpress using REST API
- Can I define multiple callback methods depending on the call method?
- Filter post content in REST API
- WordPress Gutenberg get page template value when post updated?
- WP Rest API convert permalink to post ID for fetch
- Does accessing WordPress via REST API affect the site stats and analytics?
- Wp Rest Api Custom Endpoint for page subpages
- x-wp-nonce is not allowed by Access-Control-Allow-Headers in preflight response
- WordPress REST API “rest_authentication_errors” doesn’t work external queries?
- How should an old API version be deprecated gracefully?
- How to get around WP REST API per page limit without pagination?
- Can’t GET draft posts via REST API from headless frontend
- How to update custom meta fields with rest api?
- Query the REST API for a Tag by slug
- Rest API Custom Endpoint with space character
- Build on same WordPress or different install?
- Testing custom API endpoint with class dependency
- Formating content rendered from wordpress REST API as JSON and not HTML
- How to properly add custom entities in Gutenberg
- apiFetch security
- REST API custom endpoint without authentication for POST method?
- CORS & Remote access to WP via RestAPI
- Create Session with JWT
- Not all featured image sizes available in Rest API
- Rest API and Custom Fields
- Full page NGINX (or Cloudflare) caching and WordPress nonces
- How to filter users on custom meta fields in WP JSON v2?
- How can I return an image from a custom REST API endpoint?
- WP REST API returns incorrect data?
- WP API ignores filter parameter
- 403 Forbidden with gutenberg
- WordPress REST API, Expired Nonce from Cache results in 403 forbidden
- How add meta fields to a user with the wp-api?
- WP Rest API: Get User by Email
- WordPress Rest API response
- Application Password is not enable by default?
- Gutenberg Custom Block Getting All Posts