If you’re using WP 4.7+ you can filter the query using the rest_$type_query
hook wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:L267
This is a working example that filters current query by given terms
$types = [
'post',
'page',
];
foreach ( $types as $type ) {
add_filter( 'rest_' . $type . '_query', 'filter_rest_query_by_zone', 10, 2 );
}
function filter_rest_query_by_zone( $args, $request ) {
$zones = [ 'term1', 'term2', 'term3' ];
$args['tax_query'] = array(
'relation' => 'AND',
array(
'taxonomy' => 'zones',
'field' => 'term_id',
'terms' => $zones
)
);
return $args;
}
Related Posts:
- wp_get_post_terms is difference obj model than the one in rest api response
- Change Dashboard URL from wp-admin to wp-admin/index.php
- Passing a parameter to filter and action functions
- Get a list of all registered actions
- WP Rest API: details of latest post including featured media url in one request?
- Preventing a plugin from updating
- Customizing subject in comment notification e-mails
- WP showing “warning: call_user_func_array()”, What to do?
- Filter Hook on plugin update
- WordPress Hook that will run when media file deleted
- Disallow a user to post in certain categories
- Generic plugin (de)activation hook?
- Adding a form at the end of the content
- Store post in raw markdown format, no html?
- Use external link in the add sub menu
- How can I add a custom meta value on file upload?
- How can I filter blog name?
- why does the add_action(‘the_content’) overwrite my page
- Fatal error: Class not found in
- REST-API: extend media-endpoint
- Showing Notifications While Activating Plugin
- Woocommerce Shipping module available only for type of products [closed]
- WordPress Plugin Boilerplate – add_action hook in static “activate” function
- Put code into body tags near top, using a plugin
- Keep user’s privileges on accessing contents in JSON response
- Hook before & after plugin / core update
- publish_post plugin hook doesn’t always pass $post->post_content
- How to retrieve custom meta term of category taxonomy from WP Rest API?
- get_plugins() doesn’t work after plugins_loaded
- add_action in functions.php, do_action in plugin?
- add action for displaying posts using a shortcode
- Randomize attachment IDs
- Are there hooks for WordPress updates?
- Plugin activation hook in an abstract class
- Remove rewrite rules generated by plugin during deactivation
- Change permalink structure hidden button edit
- WordPress filter that hook after each action/filter hook
- When to use action hooks and plugins
- Is there an earlier hook than login_head or login_enqueue_scripts?
- Gravity Forms plugin: How to use “gform_editor_js” action hook? [closed]
- Map a custom id to wordpress post id
- Calling plugin function inside custom plugin for onclick event
- How to modify WCMP Rest API response?
- get current date + 90 days and checking every day
- Calculate price and display on woocommerce product single page under price (simple price, variable price) [closed]
- Ability to make API calls out of WordPress as well as executing SQL?
- Ajax with plugins returns 0
- Hook into existing tinyMCE button
- How to get post ID with hooks publish_post, new_to_publish, etc
- Add sub menu page in your plugin
- how to change automatic placing of social plugins below content?
- the_post hook is not firing for me
- Deactivate JS Script in Plugin Shortcode
- Plugin Development – Functions or Hooks?
- Adding Plugin Assets to Header
- Add item to the woocommerce dashboard menu from a plugin
- How to create WordPress custom end point with multiple parameters?
- What are admin hooks
- How do I add $_SESSION[”] to my wordpress page?
- How to use filter to disable adding a product to wishlist?
- WordPress: Add custom add_filter for custom functions
- Function added to hook “new_to_publish” not executing – custom plugin
- Hook for plugin to insert into entry-meta
- Use a hook or filter, or overwrite this Gamipress function?
- Hook from plugin doesn’t fire up from external PHP script
- How to send the featured image of a post to an API?
- Is there a hook similar to “save_post” which only fires AFTER the post is completely published?
- Randomize post (and page) IDs on generation
- save_post hook partly firing in update post
- My plugin runs on every single WordPress page, but I want it to run only on activation
- The function called on the wp head hook becomes null
- Show post object of any page in frontend
- add tags to wordpress post using REST API
- WordPress output data to another website and pull data
- Hide response returned from WordPress REST API call
- How achive serving multiple concurrent Ajax / Rest calls in plugin?
- Use action, filter, or hook to append HTML to WordPress plugin function
- Modifying server’s response to API endpoint
- Passing function into add_action always returns the first argument
- Hook to display element as product on category page
- Is it possible to disable a theme programmatically?
- Fetching users data from REST API
- Consume legacy rest api dependent upon WP API plugin
- plugin not hooking to my custom hook
- wp_login_form() ignoring login_form action hook
- How to do rest APi with wordpress
- Modify a plugin’s content
- Plugin hook breaks new WP 4.0 media library grid view?
- Variable scope in plugin outside loop [closed]
- Checking url from plugin [duplicate]
- Extend WordPress REST API with Scheme Pro Plugin
- User register hook can’t access form request
- WordPress Hooks : Where to place callbacks that repetitively yield the same effect?
- wordpress Ajax success doesn’t return the value
- Can’t use updated variables in handle function
- Social login authentication via wordpress rest api
- Is option_active_plugins actually doing anything useful?
- Is it possible to create post in wordpress using postman?
- Block Root REST API Route using custom &/or iThemes
- Accessing Correct Database to Create REST API Endpoint