Skip Navigation

[Resolved] Conditional output based on post relationships dosent work

This support ticket is created 5 years, 9 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.

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 11 replies, has 2 voices.

Last updated by Christian Cox 5 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1227869
13.PNG
12.PNG

I am trying to:
To display a form inside a CPT 1 conditionally based on another field of CPT 2. Both posts are related as one to many.

I reading this guide:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/conditional-output-based-on-post-relationships/

I expected to see:
The form

Instead, I got:
Blank area.

Thank you for your help.

Code im using


{!{wpv-conditional if="( $(wpcf-approve-field).id(approve) eq '3' )"}!}

{!{cred_form form='inform'}!}{!{cred_form form='send-to-print'}!}

{!{/wpv-conditional}!}


#1227917

Hi, can you tell me:
- What are the two post type slugs?
- What is the slug of the relationship?
- Which post type is the parent (one) and which is the child (many)?

#1227926

Hello,
- CPT: job & approve
- Relationship: signature
- Parent is JOB & and child is APPROVE

Many thanks

#1227927

In the Approve post, this syntax should allow you to check the approve-field value in the Job post parent:

{!{wpv-conditional if="( '[types field="approve-field" item="@signature.parent" output="raw"][/types]' eq '3' )"}!}
 
{!{cred_form form='inform'}!}{!{cred_form form='send-to-print'}!}
 
{!{/wpv-conditional}!}

If that's not working as expected, please turn on debug mode and let me know what you see on the front-end of the site:

{!{wpv-conditional if="( '[types field="approve-field" item="@signature.parent" output="raw"][/types]' eq '3' )" debug="true"}!}
 
{!{cred_form form='inform'}!}{!{cred_form form='send-to-print'}!}
 
{!{/wpv-conditional}!}
#1227935

It is still blank.

Debug gave me this:

####################
wpv-conditional attributes
####################
Array
(
    [if] => ( '' = '3' )
    [debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( '' = '3' )
--------------------
After replacing 1 general variables and comparing strings: ( '' = 3 )
	Comparing  to 3
#1228035

Okay the conditional isn't finding the approve-field field successfully. Please add some additional debug information before the conditional and let me know what you see on the front-end:

{!{wpv-post-title}!}: {!{wpv-post-type}!}<br />
{!{wpv-conditional if="( '[types field="approve-field" item="@signature.parent" output="raw"][/types]' eq '3' )" debug="true"}!}
  
{!{cred_form form='inform'}!}{!{cred_form form='send-to-print'}!}
  
{!{/wpv-conditional}!}
#1228101

I get this info:

Test 999: job<br />

####################
wpv-conditional attributes
####################
Array
(
    [if] => ( '' = '3' )
    [debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( '' = '3' )
--------------------
After replacing 1 general variables and comparing strings: ( '' = 3 )
	Comparing  to 3


Would you like login credentials?

#1228105

So the current post is a JOB, not an APPROVE post. My suggestion was for use on the Approve post, as I mentioned here: https://toolset.com/forums/topic/conditional-output-based-on-post-relationships-dosent-work/#post-1227927

Where is the approve-field custom field - on the JOB post or on the APPROVE post?

#1228161

The approve-field is part of the Approve post. Im trying to use this inside a JOB post as it is related. Any ideas why it dosent show up?

Thank you

#1228187

Yes, please review the notes here:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/conditional-output-based-on-post-relationships/

In the second dropdown all existing relationships will be displayed. For conditional output you can only use One-to-One (1:1) and One-to-Many (1:M) relationships. It is important to keep in mind that you can compare only to values coming from the “One” part of the relationship. Comparing to the “Many” side will produce no results because Toolset cannot know which of the many items you want to compare to.

You cannot use this syntax to display information about Approves within a Job, because Approve is the "many" side and Job is the "one" side. You must use a View of Approve posts inside the Job post. Add a post relationship Query Filter, set by the current post. Then in the loop, you can display information about all the related Approve posts.

#1228196

I see but how in my case displaying all related approve posts will help me? I only want to conditionally display a general form based on the that particular custom field value.
But i guess that article explains that is impossible to do that. Is that correct ?

#1228197

I only want to conditionally display a general form based on the that particular custom field value.
There is no one particular custom field value, because there can be several matching posts. Please re-read that statement and let me know if you understand.