Skip Navigation

[Resolved] How do I wrap a post reference inside of a conditional?

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.

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 1 month, 2 weeks ago.

Assigned support staff: Waqar.

Author
Posts
#2437243
related-page.jpg

I have a custom post type, VIDEOS

One of the fields for a video post is "Related Page". This is set up as a "Post Reference" which lets me pick any other page on the website.

On my video content template, I know that I can display a linked title of the related page like this:

<h3>Related Page</h3>
{!{wpv-post-link item="@related-page.parent"}!}

However, not all videos have a related page. I only want to show the <h3>Related Page</h3> header if there's actually a related page that will be displayed.

Is there a simple way to use conditionals to check for whether or not this video has a Related Page? Something like

IF this video's related page field isn't blank
THEN show <h3>Related Page</h3> and the wpv-post-link

Thank you!

#2438029

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

You can use the [wpv-post-id item='@related-page.parent'] in a conditional statement, to check whether the ID of the related page is equal to empty or not:
https://toolset.com/documentation/legacy-features/views-plugin/using-shortcodes-in-conditions/

For example, the following conditional statement will only show the enclosed content, if the related parent page's ID is not equal to 'empty':


[wpv-conditional if="( '[wpv-post-id item='@related-page.parent']' ne '' )"]

<h3>Related Page</h3>
[wpv-post-link item="@related-page.parent"]
  
[/wpv-conditional]

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar