Skip Navigation

[Resolved] auto fill child post title with parent title

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

Problem:
In the CRED form for creating child post, automatically fill the post title ([cred_field field="post_title" ... ]) with parent post title
Solution:
Use CSS codes to hide the post_title field which outputted from CRED shortcode:
[cred_field field="post_title" post="contactformulier" value="[cred_post_parent get='title']"]
Relevant Documentation:
https://toolset.com/documentation/user-guides/cred-forms-for-child-content/

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

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
- 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)

This topic contains 4 replies, has 2 voices.

Last updated by eliseD-2 7 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#413954

I have created a CRED form that creates a child post, and I would like to automatically (and invisibly) fill the title of the child post with the same title as the parent post.

I saw a thread that suggested this :
[cred_field field="post_title" post="contactformulier" value="[wpv-post-title id='$parent']"]
But even if this works, it would show the title on the form (for the user to see), right?

I tried adapting some code I saw in another thread like this:

//Shortcode to get current page title as title of child post (for CRED form relationships)
add_shortcode('current-parent-title', 'current_parent_title_func');
function current_parent_title_func($atts, $content){
$queried_object = get_queried_object();
$title = get_the_title($queried_object);
return $title;
}

[cred_generic_field field="_wpcf_belongs_answer_title" type="hidden" class="" urlparam=""]
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[current-parent-title]"
}
[/cred_generic_field]

But I'm not convinced this will work because the "_wpcf_belongs_answer_title" doesn't seem right.

My parent CPT is called TEST and my child CPT is called ANSWER.

Can you help?

Thanks!

Elise

#413993

Dear Elise,

In your case, I suggest you try one of below two options:
1) Use CSS codes to hide the post_title field which outputted from CRED shortcode:
[cred_field field="post_title" post="contactformulier" value="[wpv-post-title id='$parent']"]

2) If you need use cred_generic_field, then you will need setup custom PHP codes to save it as the post title, for example use CRED action hook:
cred_save_data
https://toolset.com/documentation/user-guides/cred-api/#csd
This hook allows doing a custom action when post data is saved to database.

#414268

The first option is so simple and elegant ... but there is still one problem (that I might not be able to fix?)

Because this is on a create-child-post form, I guess the post doesn't officially have a parent yet - so when I use the code from your #1 above, it returns the title of the PAGE that the Cred form is on, rather than the title of the PARENT of the child post.

Is there anything I can do about that?

Thanks!

Elise

#414368

In the CRED form for creating child post, you can use CRED shortcode [cred_post_parent get='title'] to get the parent post title, see our document:
https://toolset.com/documentation/user-guides/cred-forms-for-child-content/
section "Information about Parent Pages"

#414623

Thanks.

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