Skip Navigation

[Resolved] Create the title of posts from the name of their author

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

Problem:

Is it possible to have the title of a professional's custom post (his professional profile) automatically created from his first and his last name (i.e. the name of the WordPress author)?

Solution:

You can consider custom codes, for example:

https://toolset.com/forums/topic/create-the-title-of-posts-from-the-name-of-their-author/#post-2119497

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created 3 years, 5 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by dominiqueM-3 3 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#2119229

Tell us what you are trying to do?
I work on a professional directory.

In fact, I would like to reproduce the Toolset contractors directory almost identically.
For that I try to follow the procedure explained in this tutorial: https://toolset.com/lesson-placement/lesson-placements-1622969-1929573/?utm_source=pocket_mylist

Professionals' content type is created and professionals can create their profile through a front-end custom post creation form.

Here is my question:
Is it possible to have the title of a professional's custom post (his professionnal profile) automatically created from his first and his last name (i.e. the name of the WordPress author)?

For example, if the logged in user is Simon Delmotte, I would like the title of the custom post for his profile to be Simon Delmotte.

Thank you

#2119497

Hello,

There isn't such kind of built-in feature, you can consider custom codes, for example:
1) After user submit the post form, use action hook cred_save_data to trigger a PHP function:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

2) In this PHP function, get current post author's user ID:
https://developer.wordpress.org/reference/functions/get_post_field/#comment-2906
Then get their first name and last name:
https://developer.wordpress.org/reference/functions/get_the_author_meta/
And use above values to update current post's title:
https://developer.wordpress.org/reference/functions/wp_update_post/

#2119797

Hi Luo,

Thank you for your support,

It is working for me with the following code.
I'm not a developer so I hope it is correct.

//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']==37) {
$author_id = get_post_field( 'post_author', $post_id );
$last_name = get_the_author_meta( 'last_name', $author_id );
$first_name = get_the_author_meta( 'first_name', $author_id );
$title= $first_name . ' ' . $last_name;
$args = array('ID' => $post_id, 'post_title' => $title);
wp_update_post($args);
}
}

Regards

#2119809

My issue is resolved now. Thank you!