Skip Navigation

[Resolved] Set Post Title = Concact Custom Fields

This support ticket is created 3 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 4 replies, has 2 voices.

Last updated by Minesh 3 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#2033775

Hi,

how can I automatic set the Post Title as a Custom Fields Concatenation?

For example:
Post Title = post_id + ' : ' + my_custom_field_lastname + ' ' + my_custom_field_name + ' ' + my_custom_field_role
Post title = "12 : Black Jack Manager"

Regards
Alex

#2033873

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I would like to know when you want to generate dynamic post title usinng the custom fields value - is it using Toolset form? If yes:
- You can use the Toolset Form's hook "cred_save_data" to generate the dynamic post title based on your custom fields.

For example - You can add the above custom code to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

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) {
        $name = get_post_meta($post_id, 'wpcf-name', true);
        $email = get_post_meta($post_id, 'wpcf-email', true);
        $title= $name. '-' . $email;
        $args = array('ID' => $post_id, 'post_title' => $title);
        wp_update_post($args);
    }
}

Where:
- Replace 9999 with your original form ID.
- And adjust the code as required.

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

#2035059
Immagine 2021-04-28 091650.jpg

Hi Minesh,

thank you for you reply.
I mean in admin, when you add a new custom type item.
for example:
I've a Custom Type "MyUser" with 3 Custom Fields (Number, Name, Lastname).
When I add a new "MyUser" I type Number (034), Name (John), Lastname (green) and I need that the "post title" is filled in automatic with "034 - John Green".

I don't know if I'm clear....

Regards
Alex

#2035071
Immagine 2021-04-28 091650.jpg

Hi Minesh,

thank you for you reply.

I mean in wordpress admin... when i add a new "custom type" record.
For example:
I've a "custom type" called "MyUsers" with 3 "custom type fields": myuser_number, myuser_name, myuser_lastname
When I add a new "MyUser" I need that the "post title" is automatic filled with the concatenation of this 3 custom fields.
myuser_number : 034
myuser_name : John
myuser_lastname : Green
post_title : 034 - John Green

I don't know if I'm clear...

Regards
Alex

#2035159

Minesh
Supporter

Languages: English (English )

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

That means you want to generate the post title when you save/publish post on backend.

For that, you will require to uses the WordPress standard hook: save_post

Please check the following related ticket where I shared the related solution. You may have to change the code as per your requirement:
=> https://toolset.com/forums/topic/add-auto-generate-post-title-from-fields/#post-1213144

More Info:
=> https://toolset.com/documentation/customizing-sites-using-php/updating-types-fields-using-php/