Skip Navigation

[Resolved] search panel for user view

This support ticket is created 7 years, 4 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 13 replies, has 2 voices.

Last updated by oliverD 7 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#549208

I am trying to:
How can I create a search panel for a user view? Can you make the site from this post available again?
Thanks
Oliver

I visited this URL:

I expected to see:

Instead, I got:

#549329

Q1) How can I create a search panel for a user view?
I assume you are going to setup the parameter search form a in user view, there isn't such a feature with Views plugin yet, when you edit a user view, in section "Custom Search Settings", you will be able to see the message:
Only Views listing posts can have custom search inputs.

Q2) Can you make the site from this post available again?
Could you describe more details for the question?
Which site and post are we talking about? I need more details, thanks

#549368

Is there anyway to build a search panel of users in a view?
You created a test site for someone sometime ago with an example, I cannot find the link now.

#549373

As I mentioned above, there isn't such a built-in feature within Views plugin, Views is using WordPress class WP_User_Query to query users, you can setup custom filters with filter hook "wpv_filter_user_query", see our document:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_user_query

You can create your own test site in http://discover-wp.com/, but it does not support custom PHP codes.

#549396

Can you share a good example that I could build on?

#549404

Here is an example for using filter hook "wpv_filter_user_query":
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_user_query
click "Usage examples"

For example this thread:
https://toolset.com/forums/topic/displaying-all-users-with-views/

#549460

I am not sure how I would use this to put a search panel at the top of my user view and how I would include multiple parameters. Can you elaborate a little?

#549693

Since there isn't such a built-in feature within Views, you will need do these manually:
1) Manually create a search form with search field and submit button, put the form into the top of your user view, when user click the submit button in front-end, it will pass specific URL parameter to the view.
2) Use filter hook "wpv_filter_user_query" to add custom filters to your views
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_user_query

#549886

I have tried the following but without any luck
function find_user_email_name( $query_args ) {
//$args = array(
//'search' => 'gmail',
//'search_columns' => array( 'user_login', 'user_email' )
//);
$query_args = array( 'role' => 'Administrator' );
if ( isset( $query_args['role'] ) ) {
unset( $query_args['role'] );
}
debug_to_console(array($query_args));
return $query_args;

}
Any suggestions?

#550201

Views is using WP_User_Query to query the wordpress users, please follow document to setup your PHP codes:
https://codex.wordpress.org/Class_Reference/WP_User_Query
For example
Search Parameters
https://codex.wordpress.org/Class_Reference/WP_User_Query#Search_Parameters
User Role Parameter
https://codex.wordpress.org/Class_Reference/WP_User_Query#User_Role_Parameter

For example:

add_filter( 'wpv_filter_user_query', 'prefix_unset_user_roles', 10, 3 );
  
function prefix_unset_user_roles( $query_args, $view_id, $setting) {
    if ( $view_id == 123 && isset( $query_args['role'] ) ) {
        unset( $query_args['role'] );
    }
    return $query_args;
}

Please replace 123 with your user view's ID

#550299

And how will I pass in parameter from the search section on the view page?

#550590

As I mentioned above, you will need to:
Manually create a search form with search field and submit button, put the form into the top of your user view, when user click the submit button in front-end, it will pass specific URL parameter to the view.
And here is a document about HTML form:
hidden link

If you agree, we can take it as a feature request, thanks

#550799

Great thanks, got the bones of it working. I will develop it out.

#551566

Hi,
I have a new issue where the search is being lost during paging through the details even though the values are still in the fields. How do I maintain the search fields during the paging