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
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/
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
My issue is resolved now. Thank you!