WordPress filter hook

rest_query_vars

Fired by 6 WordPress plugins, running on 40K+ sites between them.

“Filter allowed query vars for the REST API.”

How to use rest_query_vars

It's a filter: your callback receives the value, and must return the (changed) value. Add this to your theme's functions.php or a small custom plugin:

functions.php
add_filter( 'rest_query_vars', function( $valid_vars ) {
	// Change $valid_vars here.
	return $valid_vars;
}, 10, 1 );

Argument names come from Seriously Simple Podcasting's source. Other plugins may pass different values: check the call in the plugin you're targeting below.

6 plugins that fire rest_query_vars

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. Seriously Simple Podcasting icon Seriously Simple Podcasting20,000+ installs apply_filters( 'rest_query_vars', $valid_vars ) php/classes/rest/class-episodes-rest-controller.php:1045
  2. GamiPress icon GamiPress10,000+ installs apply_filters( 'rest_query_vars', $valid_vars ) includes/api/class-wp-rest-gamipress-posts-controller.php:326
  3. WordPress REST API (Version 2) icon WordPress REST API (Version 2)10,000+ installs apply_filters( 'rest_query_vars', $valid_vars ) lib/endpoints/class-wp-rest-posts-controller.php:757
  4. Appmaker WP icon Appmaker WP100+ installs apply_filters( 'rest_query_vars', $valid_vars ) lib/endpoints/appmaker/class-appmaker-wp-rest-backend-posts-controller.php:425
  5. WP Rest Api V2 Multiple PostTypes icon WP Rest Api V2 Multiple PostTypes100+ installs apply_filters( 'rest_query_vars', $valid_vars ) lib/endpoints/class-wp-rest-multiple-posttype-controller.php:339
  6. Booking Weir icon Booking WeirFewer than 10 installs apply_filters( 'rest_query_vars', $GLOBALS['wp']->public_query_vars ) includes/core/events/EventPostType.php:832

Need a customisation built on this hook?

Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.