Skip Navigation

[Resolved] Generate post title using parent post fields

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

Problem: I would like to generate a post title using portions of the parent post title, but I only have access to the parent post ID.

Solution: Use the WordPress function get_the_title() to access the parent post title when only the parent post ID is known.

Relevant Documentation: https://developer.wordpress.org/reference/functions/get_the_title/

This support ticket is created 4 years, 1 month 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)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by jamesR-13 4 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1896679

I am trying to generate a post title from fields in the cred post form, specifically, i want to have the parent post TITLE field as part of my child post title.

Is there any documentation that you are following?

https://toolset.com/forums/topic/get-parent-post-data-and-create-child-post-title-using-cred-form/

Here is the code I am using, that currently returns the parent post ID. I just need to know if there is a way to specify that I want the TITLE instead of the ID of the parent. Please and thank you:

$parent_post_id = $_POST['@client-client-portfolio_parent'];

#1896805

It sounds like you need the post title, but you only have access to the post ID. You should be able to get a post title given the ID using WordPress's function get_the_title: https://developer.wordpress.org/reference/functions/get_the_title/

$parent_post_id = $_POST['@client-client-portfolio_parent'];
$parent_post_title = get_the_title($parent_post_id);

Then use the variable $parent_post_title as needed instead of $parent_post_id to construct the child post title.

#1899721

My issue is resolved now. Thank you!