Skip Navigation

[Resolved] Output Custom Fields conditionally from current post, inside a View

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

Problem: I have some conditional custom fields. If custom field A has option 1 selected, I want to display custom field B's value on the current post. If custom field A has option 2 selected, I want to display custom field C on the current post.

Solution: There's no need for a View since you're placing these shortcodes on the single post page. The Types and Views shortcodes will display information about the current post, by design. Move your conditionals into the Content Template.

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
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 26 replies, has 3 voices.

Last updated by Ben 6 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1122902

Ben

I have set up a CPT of Countries and have attached three Custom Field Groups to it. I have two Custom Field Groups that are displayed conditionally dependant on the value of a Custom Field in the static CFG. Both of the conditional CFGs contain CFs that are URLs.

I want to be able to display the URLs of whichever CFG is displayed conditionally.

I was thinking there might be two ways to achieve this.

To have some sort of method where all the CFs from both conditional CFGs are displayed and hide the blank ones. I'm not sure there's a way of doing this with Toolset though?

Or using Views and creating three separate Views. One each to display the CFs from each conditional CFG. Then creating another one to hold both and using the conditional logic from within Views to display the View that is required. However, I cannot find a way from within Views to Query only the current CPT.

Is there a way to do this with Views? Or is it better to start somewhere else altogether?

Thank you kindly in advance.

#1123519

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - as I understand, you want to query specific post ID that belongs to specific post type? If Yes, yes, you can filter your view by specific post ID.

More info
=> https://toolset.com/documentation/user-guides/filtering-views-query-by-post-id/

If this is not what you are looking for, I need more details about your requirement with few screenshots that will help mt to understand your issue and based on that information I will be able to guide you in right direction.

#1123610

Ben
Static CFG.png
Cond CFG2.png
Cond CFG1.png

Hello Minesh,

I don't believe that is what I am looking for. Let me try to explain better. I have included screenshots to help.

I have a Static CFG set up with a CF of "Type". This allows selection of either Type 1 or Type 2.

I then have other CFGs set up to display conditionally based on the selection of the Type CF from the Static CFG.

Using these, each post has an URL attached to it, either of Type 1 or Type 2 (dependant on the selection in the Static CFG).

I want to be able to design a View (or achieve it some other way) that I can use on a template for the post type, to display the URL that the post has attached to it.

Does that make any more sense?

#1123658

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As I understand, Within view/content template you want to display:

If Type 1 Selected:
-- Display Type 1 link
If Type 2 Selected:
-- Display Type 2 link

If yes - what if you try to use [wpv-conditional] shortcode.

For example:

[wpv-conditional if=" '[types field="type"][/types]' eq 'Type 1' "]

Type 1 Link:[types field="type-1-link"][/types]

[/wpv-conditional]

[wpv-conditional if=" '[types field="type"][/types]' eq 'Type 2' "]

Type 2 Link:[types field="type-2-link"][/types]

[/wpv-conditional]

More info:
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

#1123819

Ben
Minesh Suggested View.png
My View.png

Thanks for that Minesh. I was trying something similar with Views by myself but neither your version nor mine seem to work.

I used all the config from Post 1123610.

Screenshots attached so you can see the setups and outputs.

In both Test Type 1 and Test Type 2, both Views show both links 1 and 2 for each page, when I expected it to show Link 1 for Type 1 and Link 2 for Type 2.

Can you see what is wrong?

#1124336

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - do you mean that you want to fetch the values of Type 1 and Type 2 from post-ID 1123610 ?

#1124493

Ben
Screenshot 2018-10-10 at 10.58.07.png

No Minesh. Post 1123610 was in reference to the reply on here (please see attached).

I want to fetch the values from Test Type 1 and Test Type 2 as shown above in reply 1123819. In the same reply I mention two Views. One that I tried myself using Views conditional options, and another that you suggested. The output of these two Views is also shown there with my explanation of what I was expecting to see.

Does that make any more sense?

#1124518

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - could you please share problem URL and access details so I will dive into your site and look whats going wrong there.

I have set the next reply to private which means only you and I have access to it.

#1124548

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - when I try to access wp-admin, it shows 403 Forbidden page. Could you please send me the working wp-admin.

Could you please also share the problem URL where you added the view.

I have set the next reply to private which means only you and I have access to it.

#1124572

Ben

Minesh, if you haven't finished this request by the time you finish work today would you mind transferring it to a Supporter in my timezone?

It's nothing personal, your support is brilliant! Just that I lose half a day of support due to the time zone difference.

#1124590

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - it still give 403 page error for me and one of my colleague. I'm still here if you share working access details, if I will not get working access details in next reply, I will pass this ticket to another supporter as per your request.

I have set the next reply to private which means only you and I have access to it.

#1124594

Ben

Minesh, I'm really not sure why you are getting a 403. Could you send us a screenshot of what you see and I can look into it? I can't see anything my side that could be causing a 403.

#1124611

Ben

I have no idea why you or your colleague are seeing that.

Let me try and figure it out this end. In the meantime could you transfer the ticket another Supporter if possible? Someone ideally around GMT -04:00 or -05:00 would suit great. The only reason I request a change of Support is the timezone difference. Thank you for all your help with this. You have been brilliant!

Could you also please delete reply 1124600 or the Nimbus screenshot.

Thank you again Minesh!

#1124745

Ben

Hello Christian,

Could you let me know what you see when you try to login please.

#1124767
403.png

I see a 403 error when I go to /wp-admin, so I'm not able to log in. When I go to the root, I see a "Coming Soon" page with a large image of London, showing the London Bridge. Screenshot attached with URL obscured.