Skip Navigation

[Resolved] display certain custom post type based on logged in user

This support ticket is created 6 years, 1 month 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 10 replies, has 2 voices.

Last updated by Luo Yang 6 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1130128
Screen Shot 2018-10-18 at 2.04.10 PM.png

I have a question, just to see if this is in the capabilities of toolset types.

I have many users, and I have a custom post type named INSTITUTION, which we use the featured image as a place to display the company logo.

I need to connect the 2 somehow, so that when the user is logged in I can display the INSTITUTIONS logo on a page.

Yes, I could just make it a custom user user field. But that would be to much work as there will be multiple users per INSTITUTION. So if an INSTITUTION had 10 users, I would have to enter a logo for each user. Thats seems a little over kill.

So lets say an INSTITUTION c post type had a LOGO and a list of locations.

When a user connected to that INSTITUTION logged in they would be shown there logo and the list of locations.

you can see based on the screen shot (a hardcoded mockup) that I am logged in as Bobby and that my INSTITUTION is CARTER CREDIT UNION.

I need it to be able to change based on the user logged in ... So if MIKE was part of ABC Bank, and he was logged in, the info unbder YOUR INSTITUTION would be the logo of ABC BANK etc etc

is this possible with toolest types ?

#1130512

Hi,

You can setup a custom select user field, for example "my-institution", with options:
- ABC BANK
- institution A
- institution B
...

Create a content template, use wpv-conditional shortcode to check the "my-institution" field value of current logged in user, and display different image. see our document:

for example:

[wpv-conditional if="( '[types usermeta="my-institution"][/types]' eq 'ABC BANK' )"]
Display ABC BANK images here
[/wpv-conditional]

More help:
https://toolset.com/documentation/user-guides/displaying-wordpress-user-fields/
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-custom-functions-in-conditions/

#1130727

That would work, but I would have to set up a different view for each institution. We have over 200 Institutions already as a custom post type. With tons of data.

Wouldnt this need to happen at the filter level? So the filter would only pull in the institution based off the logged in user?

So i need to filter out the one custom post type post (institution) and only display the information based on if the logged in users email (or username) matches the list of emails or usernames i have set up as a custom field in the institution post type.

I was thinking about creating a custom field within the institution that would hold the emails of the users of that institution and then run a check at filter level....

if LOGGEDIN_USEREMAIL matchs CUSTOMFIELD_USEREMAIL then display the INSTITUTION info

im just not sure how to do that query, if its even possible.

#1130734
Screen Shot 2018-10-19 at 10.58.05 AM.png

see the image i attached. I am using a filter that checks to see if the manually entered email ( bwilson@ ) matched any of the emails in the custom field.....

and it works... I just need to check that using the current logged in users email, not manually enter the email.

#1131674

To check custom logged in user's email, please check this document:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/#checking-for-the-current-user-data
Checking For The Current User Data

You can get current user's email address with shortcode [wpv-current-user]:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-current-user

For your reference.

#1132080

right but i cant put a short-code into the filter query (string) . so how do I query the custom post type based of a custom field (logged in user email) of that custom post type?

I will read the documentation you sent over and see if it makes any since to my tiny brain lol

#1132531

As you can see, you can get the current logged-in user's email with shortcode:
[wpv-current-user info="email"]

Then pass it to your post view as shortcode attribute "useremail"
[wpv-view name="my-view-name" useremail='[wpv-current-user info="email"]']

And setup the filter as in your post view as below:
Select items with field:
my-filed is a string equal to VIEW_PARAM(useremail)

More help:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/#accessing-the-arguments

#1132860
Screen Shot 2018-10-23 at 12.37.54 PM.png
Screen Shot 2018-10-23 at 12.11.31 PM.png
Screen Shot 2018-10-23 at 12.06.47 PM.png

im confused.... do i need to create 2 views ?

what do i put in the constant box ? ( see image )

Again ... conditional output WONT work ( unless I am missing something) ... since the query is already ran before the conditional output is ran ... I need to only pull the custom post type entries based on the current users email ...

i think you are misunderstanding what I am trying to do.

also i attached another image showing you what i did. which gave me an error ..

I also attached an image of me trying to use a conditional statement ... which does not work either ..

#1133174

It needs only one post view.
You need to filter the post view by custom field "Associate user" = "Shortcode attribute" + "useremail", in the input box, use the attribute name: usermail

See the document I mentioned above:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/#filters-by-custom-fields
In the second line, select URL Paramter or Shortcode attribute. This means that the value is not hard-coded in the View, but will come from the page’s URL or an attribute in the View shortcode

If you still need assistance for it, please provide a test site with the same problem, also point out the problem page URL and page URL, I can setup a demo for you, thanks

#1134438
Screen Shot 2018-10-25 at 1.58.01 PM.png
Screen Shot 2018-10-25 at 1.37.10 PM.png

I cant give you access. we deal with financial institutions and are pretty much on lockdown.

see my image and please tell me if this is correct.

for testing, the only thing I have showing to output right now is the featured image of the CPT - [wpv-post-featured-image size="full" output="url"]

when i do the query like you said, its not filtering out anything as its showing me every CPT featured image, see the second image ..

but lets start with the query, is whats in the image correct ?

#1134805

Sorry, there is a typo in my answer, you need to use same attribute name "useremail" in your screenshot, and display the view's shortcode like this:
[wpv-view name="my-view-name" useremail='[wpv-current-user info="email"]']