Skip Navigation

[Resolved] Feature request : auto generate title from custom fields

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

Problem:
auto generate title from custom fields in backend admin

Solution:
You can use standard WordPress hook "save_post" in order to generate dynamic post title.

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/feature-request-auto-generate-title-from-custom-fields/#post-1152958

Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/updating-types-fields-using-php/

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
- 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)

Tagged: 

This topic contains 9 replies, has 3 voices.

Last updated by Marcel 6 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#1151323

I would like to be able to auto generate a meaningful title from custom fields.

For example, at the moment, I'm using Toolset to make a simple booking plugin. Some of the fields I'm using are date / time and name. I would like to select to auto populate the title field with those custom fields, since filling in the title manually is an unnecessary step and if I let users do that themselves, the titles won't have the same format.

I found some topics of other users doing this with custom code, but I bought Toolset so I don't have to use custom code... since it seems to be possible with a little bit of code, it shouldn't be a lot of trouble to implement a select in Toolset should it?

#1151328

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - we already offer hooks to customize your title and it provides the more dynamic way to customize your title so you can use custom field, taxonomy term values to customize it so its not required.

Please use the hooks we offer for now.

#1151329

Hi Minesh,

Thanks for your quick respons. I'm not that familiar with hooks, how do I use those?

#1151369

Minesh
Supporter

Languages: English (English )

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

Well - you should follow the Docs where Hook reference is added or contact our support if you need any help anytime.

so, once you are clear with your requirements to auto-generate the title, feel free to contact me, I will be happy to guide you.

#1151468

In this case, I have a "name" field and a "date" field. I would like the title to be auto generated as "name - date".

So for example, i have a client named Minesh and he would like to make a reservation on 23th of november. Then the title should be "Minesh - 23-11-2018".

#1151733

Hi,

Minesh is on vacation, you will get answer in next working day, it should be Monday.

#1152958

Minesh
Supporter

Languages: English (English )

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

you can use standard WordPress action save_post in order to customize yoru title.

Considering the custom fields created using Types:
For example:

function func_generate_custom_title( $post_id ) {
 
    $post_type = get_post_type( $post_id );
 
    if ( $post_type == 'your-post-type-slug'  and is_admin()) {

  $name=   get_post_meta($post_id,'wpcf-name',true);
  $date = get_post_meta($post_id,'wpcf-date',true);
  $format_date = date("d m Y",$date);

       $custom_title = $name." ".$format_date;
 
        $updated_data = array(
            'ID' => $post_id,
            'post_title' => wp_strip_all_tags( $custom_title ),
        );
        wp_update_post( $updated_data );
        } else {
        return;
    }
}
add_action( 'save_post', 'func_generate_custom_title',30,2);

Where:
- Replace 'your-post-type-slug' with your original post type slug

Please try to adjust the above code if needed.

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

#1153172

Thanks, but as I said before, I bought Toolset so I won't have to use code... I want to be able to just select the fields I want in my title, like I can with forms, views etcetera.

I know it's not possible right now, that's ok. However, I would like to be able to do this in the future. That's why it's called a feature request 😉

#1153692

Minesh
Supporter

Languages: English (English )

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

Yes - I understand what you mean and I will forward your request to our concern person who is handling feature request. If it will be approved you will see the feature request will be available for public voting at:
=> https://toolset.com/feature-request/

Please feel free to close the ticket.

#1153698

Ok thanks 🙂