Skip Navigation

[Resolved] Cannot output parent field in CRED child post using [cred-post-parent get=”id”]

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

Problem:

I am trying to output the value of a parent post field within a new / edit child post CRED form using [cred-post-parent get="id"] as below, but I cannot get it to work.

[types field='intro-line' id='[cred-post-parent get="id"]'][/types]

I have found the following threads relating to this issue but cannot see a working solution, could you advise?

Solution:

1) The child post type "Deck Events" has multiple parent post types, according to our document:

https://toolset.com/documentation/user-guides/cred-forms-for-child-content/#information-about-parent-items

If your CRED form is set to work with a child post type that has more than one parent, you must use the post_type attribute. Additionally, it is not possible to get parent information from multiple parents but only one.

So you will need to setup the shortcode, like this:

[cred_post_parent get='id' post_type='deck-event-overviews']

2) And the shortcode [cred_post_parent] does not support shortcode within shortcode feature, you can try with another Views shortcode [wpv-search-term], for example, replace this line from:

[types field="intro-line" id="[cred-post-parent get="id"]"][/types]

To:

[types field="intro-line" id="[wpv-search-term param="parent_deck-event-overviews_id"]"][/types]

3) in a single child post, you can get the parent post ID with Views shortcode:
[wpv-post-field name="_wpcf_belongs_parent-slug_id"]

Relevant Documentation:

https://toolset.com/documentation/user-guides/cred-forms-for-child-content/#information-about-parent-items

https://toolset.com/documentation/user-guides/views-shortcodes/#vf-214940

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
- 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/Hong_Kong (GMT+08:00)

Author
Posts
#615201

I am trying to output the value of a parent post field within a new / edit child post CRED form using [cred-post-parent get="id"] as below, but I cannot get it to work.

[types field='intro-line' id='[cred-post-parent get="id"]'][/types]

I have found the following threads relating to this issue but cannot see a working solution, could you advise?

https://toolset.com/forums/topic/show-custom-field-from-parent-on-child-cred-form/#post-358295
https://toolset.com/forums/topic/insert-child-post-type-field-into-existing-cred-form-2/#post-323793
https://toolset.com/forums/topic/cred-post-parent-getid-is-not-working-inside-wpv-view-namemy-view/

#615218

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - I would like to know where exactly you have added the shortcode?

Could you please share problem URL?

#615221

Okay, I'll need to share login details in order for you to see the issue - please could you send the secure form for me to fill?

#615232

Minesh
Supporter

Languages: English (English )

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

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#615391

Minesh
Supporter

Languages: English (English )

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

Well - I do not able to access the wp-admin using the user "supportuseradmin" - could you please grant me full admin rights so that I can able to check on your install.

#615519

Hi,

Minesh isn't available, I will take care of this thread.

I checked it in your website, here are what I found:
1) The child post type "Deck Events" has multiple parent post types, according to our document:
https://toolset.com/documentation/user-guides/cred-forms-for-child-content/#information-about-parent-items
If your CRED form is set to work with a child post type that has more than one parent, you must use the post_type attribute. Additionally, it is not possible to get parent information from multiple parents but only one.
So you will need to setup the shortcode, like this:
[cred_post_parent get='id' post_type='deck-event-overviews']
https://toolset.com/documentation/user-guides/cred-forms-for-child-content/#information-about-parent-items

2) And the shortcode [cred_post_parent] does not support shortcode within shortcode feature, you can try with another Views shortcode [wpv-search-term], for example, replace this line from:
[types field="intro-line" id="[cred-post-parent get="id"]"][/types]
To:
[types field="intro-line" id="[wpv-search-term param="parent_deck-event-overviews_id"]"][/types]

I have modified your CRED form "New Deck Event", you can test the result here:
hidden link

More help:
https://toolset.com/documentation/user-guides/views-shortcodes/#vf-214940

#615549

Hi Luo,

Thanks for this, I see it working on the NEW child post form now, however, the same method does not work for the EDIT child post form, I assume because there is no parent URL parameter on the edit form page.

Is possible to have a URL parameter sent through to the edit form page or do you have another way of displaying parent fields in a child post edit form?

#615562

Yes, you are right, in a single child post, you can get the parent post ID with Views shortcode:
[wpv-post-field name="_wpcf_belongs_parent-slug_id"]
in your case, the parent type slug is "deck-event-overviews"
[wpv-post-field name="_wpcf_belongs_deck-event-overviews_id"]

And get the parent post field like this:
[types field="intro-line" id='[wpv-post-field name="_wpcf_belongs_deck-event-overviews_id"]'][/types]

See the live result in your website:
hidden link

More help:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-field

#616025

Hi Luo,

This has worked though I now have a related issue.

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?

#616207

I assume the original question of this thread has been resolved, please create new thread for the new question:

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.

That will help other users to find the answers. thanks

#616306