Make a query variable public

In case you are messing with custom rewrite rules in WordPress and especially creating new ones with the generate_rewrite_rules hook, you should know how to make a private (or a custom, which is by default – non-public) query variable public in order to have it working correctly in the rewrite rule.

It’s actually pretty simple – you just need to add a new element in the array, that is filtered by the query_vars filter. Like so:

add_filter( 'query_vars', 'so_employer_var_public', 10, 1 );
function so_employer_var_public( $query_vars ) {
    $query_vars[] = 'employer';
    return $query_vars;
}

That’s all.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *