Skip Navigation

[Resolved] Filter by user’s custom field

This thread is resolved. Here is a description of the problem and solution.

Problem:
The issue here is that the customer wanted to filter a view of users based on the current logged in user's custom field data

Solution:

Set the view filter for this custom field to be filtered by a shortcode parameter.

Then you can follow the example below.

[wpv-view name='my-view' param="[wpv-user field='wpcf-year']"]

Now you need to replace param with the correct shortcode parameter name and the wpcf-year with the correct slug for the custom field. You should add the slug with the wpcf- prefix attached.

This support ticket is created 5 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.

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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 9 replies, has 2 voices.

Last updated by Kostas 5 years, 11 months ago.

Assisted by: Shane.

Author
Posts
#869392
Query Filter.png

I have a view listing users. Now I have added a new user custom field, indicating the group each user belongs.
I need to filter users by the value of current user's custom field ie list only the users of the group that current user belongs. Please see Query Filter section at attached image. I am not sure which attribute to use. Any ideas?

Thank you,
Kostas

#869587

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kostas,

Thank you for contacting our support forum.

You are filtering a post view by a value from a user custom field correct?

Please let me know.
Thanks,
Shane

#870033

HI Shane,

Thank you for responding.

Well it is the grandparent view of a three level nested view, involving users and two CPTs.
I can give you admin access if you need it.

Kostas

#870148

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kostas,

Right but I would like to know if its a value from the user you want to use to filter the view.

Also if there is a custom field on that post that matches the value on the user. Also is it the current user custom field being used to filter the View ?

Please let me know.
Thanks,
Shane

#870284

if its a value from the user you want to use to filter the view.
Yes, it is.

is a custom field on that post that matches the value on the user.
No.

is it the current user custom field being used to filter the View ?
Yes.

Regards,
Kostas

#872915

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kostas,

I Dont think we will be able to filter the posts based on a user's custom field if there isn't anything on the post that matches the value in the user field.
Thanks,
Shane

#872964

Hi Shane,

I need to filter the users (based on current user's custom field), not the posts.

Thanks,
Kostas

#872968
QueryFilter2.png

If I use the setting shown in uploaded image, I get what I want.
I just need "2017" to come from current user's wpcf-taster-group field.
Is this possible?

Thanks,
Kostas

#873593

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kostas,

I see.

What you need to do is to where you see the work constant, change it to shortcode parameter.

Then it should say the shortcode parameter to use in your view.

Finally just add this to where you are displaying your view.

[wpv-view name='my-view' param="[wpv-user field='wpcf-year']"]

Now you need to replace param with the correct shortcode parameter name and the wpcf-year with the correct slug for the custom field. You should add the slug with the wpcf- prefix attached.

Please let me know if this helps.
Thanks,
Shane

#873782

Hi Shane,

That's magic, it works!!

Thank you very much indeed 🙂

Best regards,
Kostas

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.