Hi team Toolset! Looking for a bit of an assist here if possible? Thank you
1. Tell us what you are trying to do?
I'm trying to figure out how to have autofilled dynamic post titles for a series of summits, which would then allow me to publish the posts (Slug for type is 'summit')
I'm trying to get it to read like this:
G6 2025 Xanadu Summit (Argentina)
With my fields it would be something like this
(summit-year) (summit-organization) (summit-host-city) Summit ((summit-host-country))
2. Is there any documentation that you are following?
No, trying with PHP snippets with ChatGPT to no avail
3. Is there a similar example that we can see?
No.
4. What is the link to your site?
Not available yet
Hi,
Welcome to Toolset support. This will indeed be outside of our support scope as it is a pure PHP snippet creation.
I suggest the snippet below that you can add as a custom code:
add_action( 'cred_save_data', function( $post_id, $form_data ) {
// Optional: limit to a specific post form ID
// if ( (int) $form_data['id'] !== 12345 ) return;
// Optional: also ensure we only touch the 'summit' post type
if ( get_post_type( $post_id ) !== 'summit' ) return;
// Types custom fields use meta keys wpcf-{field-slug}
$year = trim( (string) get_post_meta( $post_id, 'wpcf-summit-year', true ) );
$org = trim( (string) get_post_meta( $post_id, 'wpcf-summit-organization', true ) );
$city = trim( (string) get_post_meta( $post_id, 'wpcf-summit-host-city', true ) );
$country = trim( (string) get_post_meta( $post_id, 'wpcf-summit-host-country', true ) );
// Build: G6 2025 Xanadu Summit (Argentina)
$parts = [];
if ( $org ) $parts[] = $org;
if ( $year ) $parts[] = $year;
if ( $city ) $parts[] = $city . ' Summit';
if ( $country ) $parts[] = '(' . $country . ')';
if ( $parts ) {
$title = trim( preg_replace( '/\s+/', ' ', implode( ' ', $parts ) ) );
wp_update_post( [
'ID' => $post_id,
'post_title' => $title,
'post_name' => sanitize_title( $title ),
] );
}
}, 100, 2 );
Hook reference: https://toolset.com/documentation/programmer-reference/cred-api/
- Replace the meta keys if your field slugs differ (pattern is wpcf-{your-field-slug}).
- The code runs on create and edit submissions. If you only want to set the title the first time, wrap the wp_update_post() part in if ( get_the_title( $post_id ) === '' ).
The code above is a suggestion to help you continue the work. We did not test this on our installation.
Thanks.
Thank you so much Christopher!