Skip Navigation

[Resolved] Creating Conditional Statement Not to Display Results if Null

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/Karachi (GMT+05:00)

This topic contains 3 replies, has 3 voices.

Last updated by Waqar 1 year, 3 months ago.

Assisted by: Waqar.

Author
Posts
#2640545

Hello. I have a property listings website that has been working well for years. However, I just noticed something by chance.

I have a relationship between listings and agents. On a single listing post, when an agent is not assigned to the listing, the agent name for the listing displays the property address (which is the post title). How can I display, "No agent assigned" instead?

Here's the code I am using on the single listing view. Any help appreciated. 🙂 Eric

<h2>Contact Agent About This Property</h2>
<pee>Agent: [wpv-post-link id="$listing-agent"]<!–- [et_pb_br_holder] -–>
Phone: [wpv-post-field name="wpcf-agent-phone" id="$listing-agent"]<!–- [et_pb_br_holder] -–>
Email: [wpv-post-field name="wpcf-agent-email" id="$listing-agent"]<br />
Contact Listing Agent Now</pee>

#2640719

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Eric

If there is no connected post and the shortcode returns null, you can just check if it is an empty string, it is functionally equivalent with the wpv-conditional shortcode.

Check this legacy documentation about how to insert a conditional shortcode for fields from a related post:

https://toolset.com/documentation/legacy-features/views-plugin/conditional-output-based-on-post-relationships/

#2640749

Thank you Nigel. I checked out the legacy documentation and came up with the following. Does it look correct?

<h2>Contact Agent About This Property</h2>
<pee>Agent: [wpv-conditional if="( '[wpv-post-link id="$listing-agent"]' ne '' )"]No agent assigned[/wpv-conditional][wpv-conditional if="[wpv-post-link id="$listing-agent"]' eq '' )"]'[wpv-post-link id="$listing-agent"]'[/wpv-conditional]

#2640871

Thanks for writing back.

Yes, the format that you've shared seems correct.

Let us know if you have any follow-up questions and for a new question or concern, you're welcome to start a new ticket.