Skip Navigation

[Resolved] Autocomplete custom post type title

This support ticket is created 5 years, 9 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by valentinP-3 5 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#1198505

Tell us what you are trying to do? We are trying to insert a function to autocomplete the cpt title from two custom fields (name and surname)

Is there any documentation that you are following? Yes: https://toolset.com/forums/topic/cred-form-title-auto-fill/ - this is a topic already opened but the solution does not work for us.

#1198656

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You need to use the cred_save_data hook to modify the title after the post has been submitted.

Here is the simplest example of some code to do what you asked:

/**
 * Auto-set post title
 */
add_action( 'cred_save_data', 'tssupp_form_submit', 10, 2 );
function tssupp_form_submit( $post_id, $form_data ){

	if ( in_array( $form_data['id'], array( 123 ) ) ) {

		$first = get_post_meta( $post_id, 'wpcf-first-name', true );
		$last = get_post_meta( $post_id, 'wpcf-last-name', true );

		wp_update_post( array(
			'ID'	=>	$post_id,
			'post_title'	=> $first . ' ' . $last
			)
		);
	}
}

You would need to edit the ID of the Form (123 in the sample code), and you need to edit the keys of the fields which store the first and last names ('wpcf-first-name' and 'wpcf-last-name'; note the 'wpcf-' prefixes for Types fields).

#1198682

It works. Thank you!

#1198684

My issue is resolved now. Thank you!