Skip Navigation

[Resolved] How can I use parent content in condition checking

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

Problem:
How to check parent post field for empty value

Solution:
To check parent post field for empty value, you need to use [wpv-conditonal] shortcode.

You can find the proposed solution with the following reply:
https://toolset.com/forums/topic/how-can-i-use-parent-content-in-condition-checking/#post-404233

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/

This support ticket is created 7 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by kelvinL-2 7 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#404183

Dear Sir/Madam,

I need to check whether the parent post field contain data and display the parent image via the conditional

In the Loop Output, I put below code

[wpv-conditional debug="true" if="( $(_wpcf_belongs_host-photo_id) ne '' )"]
	[types field="host-photo" size="full" align="center" id="$host"][/types]
[/wpv-conditional]

I got the debug result

####################
wpv-conditional attributes
####################
Array
(
    [debug] => true
    [if] => ( $(_wpcf_belongs_host-photo_id) ne '' )
)

####################
Debug information
####################
--------------------
Original expression: ( $(_wpcf_belongs_host-photo_id) ne '' )
--------------------
--------------------
Converted expression: ( '' ne '' )
--------------------

Below shortcode I can retrieve the parent field host-photo if I don't put into the conditional, host-photo is an image type field

[types field="host-photo" size="full" align="center" id="$host"][/types]

What should I get from the converted expression normally?

#404192

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I think you put wrong parent post slug. You have used field slug instead of parent post slug. Could you please try following code:

[wpv-conditional debug="true" if="( $(_wpcf_belongs_host_id) ne '' )"]
    [types field="host-photo" size="full" align="center" id="$host"][/types]
[/wpv-conditional]

More info:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/
[ Section: Checking If A Parent Exists]

I hope above solution help you to resolve your issue.

#404212

Dear Minesh,

Thanks for your reply. As mentioned, I need to check whether the parent post field contain data, {host} is parent post slug and {host-photo} is the field slug.

The page will firstly query the program and then query the host associated with the program

there is an intermediary post program-and-host is the child post of program and host. In the view, I query the program-and-host with filter "Select posts that are children of the Post where this View is shown."

If you check the $(_wpcf_belongs_host_id) , it is always existed. I need to check whether the parent post's host-photo field is set.

Best regards,

Kelvin

#404233

Minesh
Supporter

Languages: English (English )

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

I understand now. you want to check "host-photo" field has assigned value or not.

Could you please try following code:

[wpv-conditional if="( '[types field="host-photo" id="$host"][/types]' ne '' )"]
    [types field="host-photo" size="full" align="center" id="$host"][/types]
[/wpv-conditional]

I hope above solution will help you to resolve your issue.

#404319

Dear MInesh,

Yes, I should directly get the field content rather than check the parent id. Problem is fixed.

Best regards,

Kelvin.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.