Hi, I've added a custom field to users "wpcf-provincias-usuario", then I've built a view to display a list of user filtered by the custom field. The query filter doesn't work, I always get the complete list of users.
I tried setting a constant value or passing a shortcode attribute, it doesn't filter correctly the users.
Can you check it?
This is the view url: /wp-admin/admin.php?page=views-editor&view_id=2088
You can find the view on /usuario/ page, it is the first view on the page. You can test with 'almeria' and 'asturia' values (the last user of the list is 'asturia').
thanks
Hello and thank you for contacting the Toolset support.
View's search is not supported for users and taxonomy views, we can only filter and search within Posts view. We intend to add this feature in an upcoming release, but it will take some time before it is implemented. We have published a tutorial on how to implement search and relationship for users using a dedicated post type. Check it here https://toolset.com/course-lesson/how-to-create-custom-searches-and-relationships-for-users/
On the other hand, you can still hook into the user's view query and modify it to introduce a search parameter. Check the wpv_filter_user_query filter here https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_user_query
And check the argument that can be passed to the underlying WP_User_Query instance here https://developer.wordpress.org/reference/classes/wp_user_query/#parameters
Check an example of using the hook on this ticket https://toolset.com/forums/topic/need-to-query-a-user-view-based-on-email/
I hope this helps. Let me know if you have any questions.
Hey, I don't want to add search filters, I've just added a Query filter (check the image).
Shouldn't it work?
The query filter should work and the view should return only the users that match the query filter.
Can you provide an example of a user that appears in the view's results when it shouldn't? I'll try to debug it from there.
I'm filtering for the constant 'almeria', so I should get only users with that value, but I'm getting one with 'asturia' (I attach a screenshot, in my first message I detailed where you can find the view).
Later, what I want to pass is the current user cusom field values by a shortcode. They could be 'almeria,madrid,granada', will it work with more then 1 value?
cheers
Thank you! I can see the issue with the user "Juan #45".
I'll need to check at the database level. Would you allow me FTP access so I can upload the Adminer script to browse the database? Your next reply will be private to let you share credentials safely.
Otherwise, I'll need your approval to take a copy of your website and debug it locally.
Hi Jamal, it seems the private message is not active.
Hey, it seems it is not private this message. Please, check it.
Hey, it seems that this message is not private.
My apologies. Now, it would be private.
Thank you!
I find out that the option "Asturias" has a similar ID to "Almeria" which makes it match the LIKE "%string%" SQL Query instruction. Check this screenshot hidden link
I wonder if this field is meant to hold multiple values? I mean, can a user has multiple values for this custom field? If no, I'll suggest using a Select field instead of a Checkboxes field.
Regarding the checkboxes field, I think, there is some kind of bug here, or it is probably an edge case. I'll need to check on a clean install. I'll get back to you tomorrow.
Ok, the user can select more then one value and I want to pass more then one to the filter.
I explain a little more what I need.
There are 'subscribers' and 'contributors' users who can check more then one Province. Then there are 'autors' users that works like province administrators. They also can check more then one province and list all the 'subscribers' and 'contributors' of their provinces.
cheers
I run a test in a clean install and I was able to have a view that takes values in a shortcode argument, separated by comma, like:
[wpv-view name="users-by-country-as-a-shortcode-argument" country="Morocco, Japan"]
You can log in to my test site with the following URL hidden link
Check the view's results here hidden link
I was able to get users that have either "Morocco" or "Japan" or both, selected in the checkboxes field.
This being said, I think that there was a glitch or a workflow issue when you were creating the values for your checkboxes field. I'll suggest that you recreate the checkboxes options again to generate random IDs for them, so they don't match an unexpected "LIKE" instruction.
Please check for the user "Juan" and the option "asturia", if it works, do the same for the other options and users. If it does not, let me take a copy of your website to check it further locally.