Skip Navigation

[Resolved] Set post title with fields from CPT Not working

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

This topic contains 1 reply, has 2 voices.

Last updated by Christian Cox 6 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1145629

Hi there,

I am BAD WITH PHP and trying to do a custom function. I want to "autofill" the post title by using two fields from a custom field group.

This is all the fields in the post group:

'[wpv-post-title]
[types field="classification-abbreviation"][/types]
[types field="classification-name"][/types]
[types field="classification-description"][/types]'

I used the following Php to add a function to autofill the tile field however it is not working.

//Create a dynamic post title by the CRED form.
add_action('cred_save_data','func_custom_post_title',10,2);
function func_custom_post_title($post_id,$form_data) {
if ($form_data['id']==9999) {
$code = get_post_meta($post_id, 'wpcf-classification-abbreviation', true);
$name = get_post_meta($post_id, 'wpcf-classification-name', true);
$title= $code. '-' . $name;
$args = array('ID' => $post_id, 'post_title' => $title);
wp_update_post($args);
}
}

It is still allocating the default fields values. I would appreciate if you could have a look and see if you can spot the error of my ways, please.

#1145973

Try changing this line to use the correct Form ID instead of 9999:

if ($form_data['id']==9999) {

You can find the correct Form ID by going to Toolset > Post Forms. If that doesn't work, I'll be glad to take a closer look.