Skip Navigation

[Closed] wpv_filter wpv_filter_user_query returns no query

This support ticket is created 2 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 2 years, 2 months ago.

Author
Posts
#2272117

I am trying to:
Alter query of wpv_filter_user_query

Link to a page where the issue can be seen:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_user_query

I expected to see:
When error logging the array $query_args The Query arguments as in WP_User_Query, array $view_settings The View settings and int $view_id The View ID I expect to see what data is passed, just like we see that in corresponding posts query filter.

However, $query_args is always an empty array, even if User view has actual Query filters.

1. Why?
2. Can we still pass our own custom filters to that view by applying hook?

Thanks

#2272243

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hey Beda!

I just set up a test on my local site with a user View.

I get some arguments passed in the $query_args parameter.

Here's my simple test code:

function tssupp_filter_query($query_args, $view_settings, $view_id)
{
    error_log('view_id: ' . print_r($view_id, true));
    error_log('query_args: ' . print_r($query_args, true));

    return $query_args;
}
add_filter('wpv_filter_user_query', 'tssupp_filter_query', 101, 3);

And this is what I get for a User View that has no query filters applied:

[21-Jan-2022 12:49:03 UTC] view_id: 255
[21-Jan-2022 12:49:03 UTC] query_args: Array
(
    [orderby] => user_login
    [order] => ASC
    [offset] => 0
    [exclude] => Array
        (
        )
)

Note the priority of 101; I've always used such a high priority when filtering post Views, and it seems to work in my case with a user View.

You should be able to update $query_args with your own arguments.

Does it work if you use a high priority?

The topic ‘[Closed] wpv_filter wpv_filter_user_query returns no query’ is closed to new replies.