Adding query variables
WordPress doesn't allow you to use any type of variable in the query string. It will check for query variables within the existing list and all other variables will be ignored. Whenever we want to use a new query variable, make sure to add it to the existing list. First, we need to update our constructor with the following filter to customize query variables:
add_filter( 'query_vars', array( $this, 'manage_user_routes_query_vars' ) );
This filter on query_vars will allow us to customize the list of existing variables by adding or removing entries from an array. Now, consider the implementation to add a new query variable:
public function manage_user_routes_query_vars( $query_vars ) {
$query_vars[] = 'control_action';
return $query_vars;
}
As this is a filter, the existing query_vars variable will be passed as an array. We will modify the array by adding a new query variable called control_action and return the list. Now, we have the ability to access this variable from the URL.