Skip Navigation

[Resolved] Change Title from CRED

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

Problem:
Change Title from CRED using custom field values

Solution:
You can use Toolset Form hook "cred_save_data" to generate the dynamic post title using the custom field values.

You can find the proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/change-title-from-cred/#post-1213002

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

This support ticket is created 5 years, 10 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by temel-tecnicas-deM 5 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#1212979
toolset problem.PNG

I am trying to set titles and permalinks with the post ID from the CRED Form, but the problem is that i think that i can not assign the ID to the title and permalink before the post is created, so it is possible to do this?

In the attached image you can see that GA3591 is the title of the post wich is correct but we want that form uses this title to set the permalink.

PD in the title the numbers are the ID of the post.

#1213002

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

For example:
- Add the following code to your current theme's function.php file
OR
- At the Custom Code section provided Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

add_action('cred_save_data', 'build_post_title', 10, 2);
function build_post_title($post_id, $form_data) {
 
if ($form_data['id']==9999) {
  
$title = get_the_title($post_id);

/// generating dynamic post title
$post_title = $title.$post_id;

// generating slug 
$slug = sanitize_title($post_title);

wp_update_post(array('ID'=>$post_id, 'post_title'=>$post_title,'post_name' => $slug));
}
}

Where:
- Replace 9999 with your original form ID

More info:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#1224400

My issue is resolved now. Thank you!