Skip Navigation

[Resolved] Generate title from custom fields

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

Problem: I would like to create a post with a title generated from its custom fields.

Solution: You can do this at 2 places, both times you will need to apply Custom Code.

1. In the backend when you create or edit a Post with WordPress.
Here you will use WordPress API "save_post" to update your Post Title with the values you have set in the Post Custom Fields.
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post

2. In the Front End when you create or edit a Post with Toolset Forms.
Here you will create a Toolset Forms that either creates or edits those posts, and includes the Fields, but not the Title.
The user of this Form will fill out the Fields, and submit the Form.
You will hook a Custom Code to the Toolset Form's API "cred_save_data()" hook, which takes the values from those fields, and updates the Post Title with it.

A simple function example that does this, crafted using this DOC (https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
), is visible here:
https://pastebin.com/2BTbVbcs

Relevant Documentation:
https://developer.wordpress.org/reference/functions/get_post_meta/
https://codex.wordpress.org/Function_Reference/wp_update_post

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

Last updated by fernandoM-9 6 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1108295

Tell us what you are trying to do?
I'm trying to create an event listing which will have a title generated from their own custom fields.

I want to create an event "Match" and I want the title to be composed from "local team" vs "visitor team" which are actually custom field from that type of content.

Is there any documentation that you are following?
Don't think so

Is there a similar example that we can see?
Don't think so

What is the link to your site?
Still working in locally

#1108765

You can do this at 2 places, both times you will need to apply Custom Code.

1. In the backend when you create or edit a Post with WordPress.
Here you will use WordPress API "save_post" to update your Post Title with the values you have set in the Post Custom Fields.
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post

2. In the Front End when you create or edit a Post with Toolset Forms.
Here you will create a Toolset Forms that either creates or edits those posts, and includes the Fields, but not the Title.
The user of this Form will fill out the Fields, and submit the Form.
You will hook a Custom Code to the Toolset Form's API "cred_save_data()" hook, which takes the values from those fields, and updates the Post Title with it.

A simple function example that does this, crafted using this DOC (https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
), is visible here:
https://pastebin.com/2BTbVbcs

This is the WordPress Codex you'll need to consult as well:
https://developer.wordpress.org/reference/functions/get_post_meta/
https://codex.wordpress.org/Function_Reference/wp_update_post

#1109004

Hello, thanks for you answer. I need a little hint about where to paste the code. In which file

Thank you

#1109094

Hi, custom PHP code should be pasted in your child theme's functions.php file. If you are not using a child theme, I strongly suggest creating one: https://codex.wordpress.org/Child_Themes

Otherwise, you can use a plugin like Code Snippets to include custom PHP code without modifying your theme's PHP files.

#1112230

Thanks for your help. It worked