Aleš Sýkora / July 11, 2019 / 0 comments

Auto-populate child content with parent content’s title

Post summary: Code snippet from our fan.

Snippet from our fan, who do not give us his name, just call him Another Unknown Toolset Fan.

This code also allows you to add the current date. If you do not want/need to display the date in the title, simply remove the shortcode, as well as well as the relevant code from the ‘post-title’ line.

// Display Current Date
add_shortcode('wpv-post-today', 'today_shortcode');
function today_shortcode() {
return date( 'F j, Y', current_time( 'timestamp' ));
}
// Auto Populate Repair
add_action('cred_submit_complete', 'auto_populate_title',10,2);
function auto_populate_title($post_id, $form_data){
// Edit form ID to match your form's ID
if ($form_data['id']==888) {
$parentpost_id = toolset_get_related_post($post_id, 'membership-vehicle-repair' );
$parent_title = get_the_title($parentpost_id);
$today_date = current_time( 'Y-m-d' );
$childpost_title = array(
'ID' => $post_id,
'post_title' => $parent_title . ' - ' . $today_date,
);
wp_update_post( $childpost_title );
}
}

Fuel my passion for writing with a beer🍺

Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻

0 comments

Share Your Thoughts