I have the following query
$args = [
'meta_key' => 'mycred_default',
'orderby' => [ 'meta_value_num' => 'DESC' ],
'order' => 'desc',
'number' => 10
];
$users = get_users( $args );
Can I make it global to access the parameters from an ajax function?
I have the following query
$args = [
'meta_key' => 'mycred_default',
'orderby' => [ 'meta_value_num' => 'DESC' ],
'order' => 'desc',
'number' => 10
];
$users = get_users( $args );
Can I make it global to access the parameters from an ajax function?
Share Improve this question asked Jan 5, 2021 at 18:03 Giselle BoyerGiselle Boyer 1 4 |1 Answer
Reset to default 1You can use the WordPress functions apply_filters
and add_filters
to store and retrieve data, like so:
// The filter callback function.
function so_wp_380975_get_user_args( $array ) {
// (maybe) modify $array.
// for now, we just return the array
return [
'meta_key' => 'mycred_default',
'orderby' => [ 'meta_value_num' => 'DESC' ],
'order' => 'desc',
'number' => 10
];
}
add_filter( 'get_user_args', 'so_wp_380975_get_user_args', 10, 1 );
// get the stored args from the filter
$args = apply_filters( 'get_user_args', [] );
Note that you can do a lot more, such as passing additional arguments to the filter to modify the args - or a default value, in case the filter returns nothing.
https://developer.wordpress/reference/functions/apply_filters/
$GLOBALS['varname']
, or send the parameters in the ajax response or other strategy. – Celso Bessa Commented Jan 5, 2021 at 19:06