Skip Navigation

[Resolved] automatically populate post title with custom fields

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

Problem:
How can I populate a Post Title with the value of a Custom field when saving a post?

Solution:
You need Custom Code.

If you use CRED; you can make usage of the CRED API cred_save_data:
https://toolset.com/documentation/user-guides/cred-api/#csd

You would use WordPress API to

get_post_meta()

the Field's Values and update the

post_title

with it.
An example:
http://pastebin.com/2BTbVbcs
Keep in mind that Repeating Fields are arrays and therfore you need a complex

foreach()

on them, to get out the single values.

If you do not use CRED, you can use full WordPress API, it will just be the same as if you would use native WordPress fields.
Then you need to hook into the

wp_update_post()

https://developer.wordpress.org/reference/functions/wp_update_post/

The only to keep in mind here too is that a Types repeating Field is an array, and therefore you need to

foreach()

over it's stored values.
http://php.net/manual/de/control-structures.foreach.php

This support ticket is created 7 years, 7 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 2 replies, has 2 voices.

Last updated by nigelp 7 years, 7 months ago.

Assisted by: Beda.

Author
Posts
#434822

Hi
I have 3 custom fields in my post type - First Name, Middle Names, Last Name.
Middle Names accepts multiple values.

Is it possible to automatically populate my Post Type's Post Title with First Name + Middle Names + Last Name

Thanks

#434945

Not without Custom Code.

If you use CRED; you can make usage of the CRED API cred_save_data:
https://toolset.com/documentation/user-guides/cred-api/#csd

You would use WordPress API to get_post_meta() the Field's Values and update the post_title with it.
An example:
http://pastebin.com/2BTbVbcs
Keep in mind that Repeating Fields are arrays and therfore you need a complex foreach() on them, to get out the single values.

If you do not use CRED, you can use full WordPress API, it will just be the same as if you would use native WordPress fields.
Then you need to hook into the wp_update_post()
https://developer.wordpress.org/reference/functions/wp_update_post/

The only to keep in mind here too is that a Types repeating Field is an array, and therefore you need to foreach() over it's stored values.
hidden link

#434978

Thanks Ill go through all of this

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.