Skip Navigation

[Resolved] Dynamic Title with Toolset Forms based on Logged in User First and Last Name

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

This support ticket is created 5 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 2 replies, has 2 voices.

Last updated by Dallin Chase 5 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#1325585

Hey guys,

I have a custom post type for applicants on my website. I'm trying to create a post with a title that is dynamically created from the current logged in users First Name and Last Name. I have it working with a custom field thanks to the code on this page (https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data) but can't seem to get it to work with the users first name and last name.

This is what I was trying.

`//Create a dynamic post title by the CRED form.
add_action('cred_save_data','applicant_post_title',10,2);
function applicant_post_title($post_id,$form_data) {
if ($form_data['id']==929) {
$firstName = get_the_author_meta($post_id, 'first_name', true);
$lastName = get_the_author_meta($post_id, 'last_name', true);
$title= $firstName. '-' . $lastName;
$args = array('ID' => $post_id, 'post_title' => $title);
wp_update_post($args);
}
}`

Any thoughts on how to do this?

I also made a video explaining if that is more helpful: hidden link

#1325593

Hello,

There should be something wrong in your PHP codes, please try to modify these two lines from:

$firstName = get_the_author_meta($post_id, 'first_name', true);
$lastName = get_the_author_meta($post_id, 'last_name', true);

To:

$author_id = get_post_field( 'post_author', $post_id );
$firstName = get_the_author_meta( 'first_name', $author_id);
$lastName = get_the_author_meta( 'last_name', $author_id);

More help:
https://developer.wordpress.org/reference/functions/get_the_author_meta/
https://developer.wordpress.org/reference/functions/get_post_field/

#1325595

Worked like a charm. Thank you Luo!