I noticed your filter function is using get_query_var()
which automatically parses URL/form parameters from the superglobals $_GET
and $_POST
, but only if the parameters are registered as public query vars.
Were you aware of that, and have you registered the orderby2
parameter as a public query var?
Because in my case (WordPress v6.1.1), the 2nd filter failed because orderby2
wasn’t a registered query var, hence the value was always empty:
$orderby2 = sanitize_text_field(get_query_var('orderby2'));
So try registering it as query var like so, which uses query_vars
:
function myplugin_query_vars( $qvars ) {
$qvars[] = 'orderby2';
return $qvars;
}
add_filter( 'query_vars', 'myplugin_query_vars' );
Note: I didn’t register orderby
because it is one of the many reserved terms in WordPress, and WordPress automatically registers it as a query var.
Or you could instead just use $_GET['orderby2']
to get the value:
$orderby2 = sanitize_text_field( $_GET['orderby2'] ?? 'all2' );