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
- How can I edit post data before it is saved?
- How can I see all the actions attached to an “add_action” hook?
- WP Rest API: details of latest post including featured media url in one request?
- Registering Class methods as hook callbacks
- How to customize woocommerce related products? [closed]
- How to include code only on specific pages?
- Changing the “Plugin Activated” Message Default
- Hooking in to plugins
- Generate dormant hook references
- Building a custom REST API
- run silex or slim with wordpress
- Schedule WordPress Auto-Updates to only run during business hours
- Better to fire specific hooks or generic hooks with parameters?
- WP JSON REST API (Ryan McCue) how to query posts with specific meta data with ‘AND’ relation?
- How to only hook on Single.php after content?
- Remove action from plugin on other plugin
- Why does wp_enqueue_style() in plugin not load stylesheet?
- Preventing a plugin from updating
- To Disable WordPress Rest API or Not To Disable?
- How To Determine If A Filter Is Called In A Sidebar/Widget Context?
- Is there any debug toolbar that shows whick hooks are called for the current page in WordPress?
- When can you get current page ID and initialize hooks right after?
- Customizing subject in comment notification e-mails
- How to save the values of checkbox to the register setting?
- Can we hook a static method of a class to add_action inside that class?
- Edit plugin without hooks in functions.php
- How can I log a user out of WordPress before the page loads?
- What is the ‘admin_action_’ . $_REQUEST[‘action’] hook used for?
- How to create gutenberg block using REST API independently or as headless way?
- WP showing “warning: call_user_func_array()”, What to do?
- How can I remove a hooked action created by a plugin?
- How to authenticate custom API endpoint in WooCommerce [closed]
- WordPress admin notice in plugin function
- Using the ‘draft_to_publish’ hook (post status transition)
- Filter Hook on plugin update
- Enqueue style inside shortcode but its loaded at the bottom of page (before footer scripts)
- Modify featured image URL at runtime
- WordPress Hook that will run when media file deleted
- Seeking clarification on page request life-cycle
- Disallow a user to post in certain categories
- Intercepting a add_action
- WordPress pods io – Rest API for fetching fields information for custom post type
- Generic plugin (de)activation hook?
- Which hook should be used to validate custom form fields on the login form?
- Reduce nonce lifespan
- Good tools for locating hooks in a wordpress page/admin interface/blog post?
- disable active plugins for specific theme
- Twillio How To Send SMS for Custom Post Type
- Hook (upgrader_process_complete) running moment
- Adding a form at the end of the content
- Hide WordPress Plugin Deactivation Links
- Add Products to user’s ID Woocommerce
- Store post in raw markdown format, no html?
- Multisite functions to communicate with individual site functions
- Find out if request is for custom post type archive before query runs
- Use external link in the add sub menu
- Pass A Value From Outside To A Plugin Variable
- Built in admin ajax hooks?
- Failed to invoke other hook from the init hook
- Does the ‘nav_menu_css_class’ filter accept 2 or 3 arguments?
- How can I add a custom meta value on file upload?
- Adding dynamic section to WordPress
- do_action and hook methods
- the_posts hook, which set of posts?
- How can I filter blog name?
- why does the add_action(‘the_content’) overwrite my page
- Fatal error: Class not found in
- Is it possible to add an action to the currently running action?
- woocommerce product attributes
- REST-API: extend media-endpoint
- How to filter content post only on save
- Filter or action hook to insert content on admin pages before tag
- Showing Notifications While Activating Plugin
- Is it possible to remove this action? (as it’s added just before it’s called)
- Accessing plugin functionality within WP REST API
- plugin_action_links_{$plugin_file} hook not in the main plugin file
- OOP: Display warning and deactivate the plugin if PHP version is less than 5.4
- Over write plugin templates
- Woocommerce Shipping module available only for type of products [closed]
- How to find out what blocks are added by a plugin
- WordPress Plugin Boilerplate – add_action hook in static “activate” function
- Determine plugin name from within plugin_action_links filter
- Put code into body tags near top, using a plugin
- How to prevent action in ajax request, when in admin side?
- merging an array to an existing array using add_filter
- template_redirect not being called when using ajax
- Permission Check for REST API Endpoint Runs Twice?
- Easy Digital Downloads (EDD) – Purchase Receipt emails couldn’t be logged
- what the hook for displaying course list page for learndash plugin? [closed]
- Keep user’s privileges on accessing contents in JSON response
- How to add rewrite rules and pagination to retrieve attachments files?
- Hook before & after plugin / core update
- Placement of Code in Plugin for hooking `save_post`
- publish_post plugin hook doesn’t always pass $post->post_content
- Can I use a method from an existing plugin as an action hook?
- Plugin custom Action Hook not working