Skip Navigation

[Resolved] Display a field in child post CRED Form only if parent post has specific value

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

Problem:
I need to only display a field in the child post cred form if the parent post has a field set to a certain value.
Solution:
Here is code:
https://toolset.com/forums/topic/display-a-field-in-child-post-cred-form-only-if-parent-post-has-specific-value/#post-616701
Relevant Documentation:

This support ticket is created 6 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
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 6 replies, has 2 voices.

Last updated by jonB-5 6 years, 9 months ago.

Assisted by: Noman.

Author
Posts
#616305

I need to only display a field in the child post cred form if the parent post has a field set to a certain value.

I'm trying the following...

[wpv-conditional if="( ($(wpcf-deck-event-vessel-selection-options).id([wpv-search-term param="parent_deck-event-overviews_id"])) eq '3' )" debug="true"]
<div class="form-group">
<label>Which Vessel/s is this listing available on?</label>
<div class="checkbox-scroll-area">
<p>Scroll for more...</p>
[cred_generic_field field='deck-event-vessels' type='checkboxes' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":[],
"options":[ [wpv-view name="dynamically-generated-list-of-vessels"] ]
}
[/cred_generic_field]
</div>
</div>

[/wpv-conditional]

Using the above, the debug result is as follows...

####################
wpv-conditional attributes
####################
Array
(
[if] => ( ($(wpcf-deck-event-vessel-selection-options).id(1523)) = '3' )
[debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( ($(wpcf-deck-event-vessel-selection-options).id(1523)) = '3' )
--------------------
After matching 2 numeric strings into real numbers: ( ('') = 3 )
Matched '3' to 3

Given that the above says Matched '3' to 3, what could be the reason for the contents of the conditional still not showing on the front end?

#616410

Noman
Supporter

Languages: English (English )

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

Hi Jon,

Thank you for contacting Toolset support. Please share your Debug Information with us so we can see it? I have enabled debug info box for your next reply:
https://toolset.com/faq/provide-debug-information-faster-support/

Please provide temporary access WP-Admin Login and FTP login info to your site. Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

✙ Please add the post link where I can see the issue.

✙ Please add the link where you have created the CRED form.

Thank you

#616701

Noman
Supporter

Languages: English (English )

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

Hello Jon,

I have added following shortcode for getting parent field value:

// Shortcode to get deck parent field value
add_shortcode('get_deck_parent_field_val', 'get_deck_parent_field_val_func');
function get_deck_parent_field_val_func() {
	if(isset($_GET['parent_deck-event-overviews_id']))
		return do_shortcode("[types field='deck-event-vessel-selection-options' id='".$_GET['parent_deck-event-overviews_id']."']");
	
}

And used following shortcode in CRED:

[wpv-conditional if="( '[get_deck_parent_field_val]' eq '3' )"]

Now condition working fine.

You can check result here:
hidden link

Thank you

#617001

Hi Noman,

I see this working now, but unfortunately the same does not work for an Edit Post form.

The following will output in the Edit form with no issue:
[types field='deck-event-vessel-selection-options' id='[wpv-post-field name="_wpcf_belongs_deck-event-overviews_id"]'][/types]

However when placed in a conditional it simply does not work and the debug box doesn't appear either.
[wpv-conditional if='( '[types field="deck-event-vessel-selection-options" id="[wpv-post-field name="_wpcf_belongs_deck-event-overviews_id"]"][/types]' eq 'Specify Vessel/s Per Route or Departure' )' debug="true"]Success[/wpv-conditional]

Could you advise on how to implement this in the Edit form?

For reference, the edit form ID is 111 and I am testing this code at the top of that form (incase you need to find it)

#617020

Hi Noman,

The issue with the Edit form appears to have been resolved with the following...

[wpv-conditional if="( $(wpcf-deck-event-vessel-selection-options).id(deck-event-overviews) eq 'Specify Vessel/s Per Route or Departure' )"] success [/wpv-conditional]

Can you foresee any issues with using this method to get the parent post ID?

#617398

Noman
Supporter

Languages: English (English )

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

Hello Jon,

This method don't have any issue. This condition was not working in CRED Create Post Form that's why I provided you some workaround.

Great to hear that you have resolved this issue.

Thank you

#620140

Marked as resolved - everything looks to be working as expected, thanks for the support!