Skip Navigation

[Resolved] Different Views filters for different Users

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

Problem: I would like to filter a View of posts using different filter values for different Users.

Solution: You can create a custom field for Users, and store the value in the custom field. Then you can pass that value into the View of posts as a shortcode attribute.

[wpv-view name="your-view-slug" filtervalue="[types usermeta='filtervalue' output='raw' current_user='true'][/types]"]

Relevant Documentation:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

This support ticket is created 6 years, 7 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 6 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#922575

thank you fir the code it's working great.

let say i have a field that gets #1 or #2 or #3 value.

how can i filter custom post by user?
i want to show to user A just post that have the value 1.
and to other user just the psot that have the value 2 and on...

please advice.

thanks rotem.

#922585

Hi, Nigel is on holiday this week so I'll be glad to help with this. It sounds like you want to filter a View by a custom field value, and you want to filter by different values for each User. Here's how I would set this up.
- Create a Users custom field that stores the value "1" for User A, "2" for User B, and so on. Make the default value empty. This will be the filter criteria for your View. I will call this field "filtervalue"
- Create a View of posts that is filtered by the other custom field you mentioned here:
let say i have a field that gets #1 or #2 or #3 value.
- Configure the custom field filter to respond to a shortcode attribute like "filtervalue". This will allow you to pass a dynamic value into the filter. This technique is called "passing arguments into Views" and you can learn more about this technique here: https://toolset.com/documentation/user-guides/passing-arguments-to-views/
- Use shortcodes to insert the View of posts and apply the correct shortcode attributes and values. Insert the "filtervalue" User field shortcode for "filtervalue":

[wpv-view name="your-view-slug" filtervalue="[types usermeta='filtervalue' output='raw' current_user='true'][/types]"]
#922614
Screenshot_4.jpg

hi thanks for the replay. i am doing something worng.

my user custom field : user-pole-number
the fillter name: pole-number
the View name: set-vote

where do i need to add the shortcode you send me?

[wpv-view name="set-vote" wpcf-pole-number="[types usermeta='user-pole-number' output='raw' current_user='true'][/types]"]

the filter string:

[wpv-control-postmeta field="wpcf-pole-number" url_param="wpv-wpcf-pole-number" placeholder=""]

thanks
rotem.

#923046

where do i need to add the shortcode you send me?
The shortcode is used to display the filtered View, so add it where you want to see the View's results. That could be in a custom Page somewhere or a Content Template, or another View.