Skip Navigation

[Resolved] Specialized access to a view

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

Problem:

I'm developing a site where a user will have a login (based upon their email address) and an a client id (in a custom field - 'client_id'). When they try to view this particular view (or any associated view) I only want them to see posts (they are from custom post type) related to their 'client_id'.

Solution:

If they are standard WordPress custom user field, you can use Views shortcode [wpv-user] to get the field value, for example:

[wpv-user field="wpcf-custom-user-field"]

Relevant Documentation:

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-user

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.

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 9 replies, has 2 voices.

Last updated by Luo Yang 5 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#1169954

Hi. I'm developing a site where a user will have a login (based upon their email address) and an a client id (in a custom field - 'client_id'). When they try to view this particular view (or any associated view) I only want them to see posts (they are from custom post type) related to their 'client_id'. If there are no items related to them then I want to display a message (ie. "sorry, no orders to show').

The logged in user will be a subscriber and I'm using Access.

They will go to the first view template which is a listing of orders. Then they will have the opportunity to click on one of them and see more details (a view archive).

I understand I need to use a conditional but I am unsure, based upon the documentation how to make this work. Can you please help? Thanks!

#1170389

Hello,

How do you setup the "client_id" field?
Is it a custom user field created with Types plugin?

How do you relate the "client_id" field with posts?
Is the "client_id" field's value correspond to post's author?

If it is, you can get current login user's "client_id" field value with Types shortcode:

[types field="client_id" user_current="true"][/types]

https://toolset.com/documentation/customizing-sites-using-php/functions/#textfield
user_current:
"true" - output user field for the logged in user
with Types shortcode

Then pass it to below post view:
- create a post view
- query posts,
- filter by
Post author is set by a Views shortcode attribute "author_id"

And display above post view, like this:
[wpv-view name=”View Name” author_id='[types field="client_id" user_current="true"][/types]']

More help:
https://toolset.com/documentation/user-guides/filtering-views-query-by-author/

Section "Post author is set by a Views shortcode attribute"

#1170703

It was not setup with Types.

#1170826

Which one is not setup by Types plugin? please elaborate the questions with more details.

1) How do you setup the "client_id" field?
2) How do you relate the "client_id" field with posts?

#1175443

1 - Nothing was setup with Types. These are custom Post Types. I just happened to be using the Toolset to create the Views.
2 - The ClientID is a custom field in the post. So I don't need to relate it. It's already there.

#1175754

If they are standard WordPress custom user field, you can use Views shortcode [wpv-user] to get the field value, for example:
[wpv-user field="wpcf-custom-user-field"]
See our document:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-user

If the shortcode is inside a Views user query, it will display information for the user found in loop. Otherwise it will display information for the current logged-in user or the user with the specific id, when id attribute is set.

#1176748

So I can use this:

[wpv-user field="wpcf-custom-user-client_id"] (thanks!)
but how can i insert a message for a user who has no results?

Larry

#1176754

Dear Larry,

If there isn't any result found in a post view, in section "Loop Editor", within shortcode [wpv-no-items-found]...[/wpv-no-items-found], you can display the message as you want.

See our document:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-no-items-found
Content wrapped with [wpv-no-items-found][/wpv-no-items-found] will be output if there are no posts, taxonomies or users returned by the View.

#1181330

My issue is resolved now. Thank you!

#1181790

You are welcome