Skip Navigation

[Resolved] User Email as View filter

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

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 15 replies, has 2 voices.

Last updated by Puntorosso 3 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1908567

When creating a View to display all users, why I cannot use the user email in the View query filter?

#1908695

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

The User email filter is not available. If you want to filter User view by user's email, it possible but you ill require to filter the view using a view's shortcode attribute and using the view's filter hook: wpv_filter_user_query

You can see the similar solution shared with the following ticket:
=> https://toolset.com/forums/topic/need-to-query-a-user-view-based-on-email/#post-1494791

More info:
=> https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_user_query

#1909009

Thanks for the suggestion, but how do I add then this query as OR value in the view?

hidden link

#1909015

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

To apply OR we will require to adjust the query on fly and for that I will require to know where you added your user view and from where the URL params coming from?

As well as I will require admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1909035

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

It seems you are trying to build a custom search but custom search is not supported for User views.

If you see the User view:
=> hidden link

You will see a notice with "Custom Search Settings" section:

Only Views listing posts can have custom search inputs.

You will require to write your custom user queries to search within first name and last name.

Please check the following link:
=> https://wordpress.stackexchange.com/questions/105168/how-to-search-for-partial-match-display-names-of-wordpress-users

More info:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_user_query

#1909039

I don't understand, the search query is already working.
I can search per name

hidden link

or per phone

hidden link

I just need to add the email to the search parameters.

#1909057

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

There is no easy way other than the modifying the where query using the hook: pre_user_query

I've added the following code to "Custom Code" section offered by Toolset:
=> hidden link

add_action( 'pre_user_query', function( $uqi ) {
 global $wpdb;
 global $WP_Views;
  $views = array( 4870 );
  if ( in_array( $WP_Views->current_view, $views ) ){
   		$uqi->query_where = $uqi->query_where.' OR (user_email LIKE "%'.$_GET['sname'].'%")';
  }
     
});

Can you please confirm it works as expected.

#1909071

Yes it does! Perfect!
Thanks a lot Minesh, for your help.

#1910723

Hi,
we just found out that the pagination doesn't work correctly when the custom function is enabled.
All names are duplicated multiple times if you press any page button.
May you have a look?

Thanks

#1912001

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As the ticket is marked resolved, the private access details is automatically removed.

Let me again inform you that User view does not offer the Custom Search but still we workaround it and I will see if I can able to find any workaround for the pagination.

I will require access details first.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1912019

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thank you for sharing access details.

Can you please share the steps I should follow to see the issue. Do I have to search with any specific keyword first and then click on pagination?

#1912027

Simply enable your php snippet, go to this page

hidden link

and try to paginate at the bottom. You will see that all users names will be shown as multiple duplicate versions.

#1912063

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now.

I've adjusted the code as given under:

add_action( 'pre_user_query', function( $uqi ) {
 global $wpdb;
 global $WP_Views;
  $views = array( 4870 );
  if ( in_array( $WP_Views->current_view, $views )  and isset($_REQUEST['sname'])){
   		$uqi->query_where = $uqi->query_where.' OR (user_email LIKE "%'.$_GET['sname'].'%")';
  }
     
});

Can you pleases confirm pagination works as expected now.

#1912095

You get the same error if you leave the search field empty

hidden link

Also, try to search for "gmail". The pagination is not working.

#1912101

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've again adjusted the code as given under:

add_action( 'pre_user_query', function( $uqi ) {
 global $wpdb;
 global $WP_Views;
  $views = array( 4870 );
  if ( in_array( $WP_Views->current_view, $views )  and isset($_REQUEST['sname']) and !empty($_REQUEST['sname'])  ){
   		$uqi->query_where = $uqi->query_where.' OR (user_email LIKE "%'.$_GET['sname'].'%")';
  }
     
});

And, you have to compromise with Ajax pagination. As we will require search keyword for pagination to display correct results when search keyword is available. So, I've set the pagination settings to "Pagination enabled with manual transition and page reload" and I can see its working for gamil as well.