Correction - this isn't resolved after all!
I have made some minor changes to my original problem and now have CPT called "Buyer" and that has some custom fields ("First Name", "Last Name" and a Post Reference Field called "Registered To").
I am not displaying the post title when creating/editing the CPT "Buyer" as I am using the code below to auto-generate the title when the post is saved. I would like the title to be First name, Last name and the title of the CPT "Registered To"
I now have 3 issue:
1 - The code works for displaying "First Name" and "Last Name", but not "Registered To"
2 - When the code is active, it is impossible to to create a new "Buyer" post (it just hangs). It is possible to edit exising "Buyer" posts, but it just hangs when you click on update.
Is there anything you can see in the code that is (A) causing the performance issue and (B) what do I need to modify in order to display the data in the "Registered To" field in the post title.
I added debugging info in my last update, but let me know if you need access to take a look at things for yourself.
Many thanks in advance.
<?php
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
function func_generate_custom_title( $post_id ) {
$post_type = get_post_type( $post_id );
if ( $post_type == 'buyer' and is_admin()) {
$first_name= get_post_meta($post_id,'wpcf-first-name',true);
$last_name= get_post_meta($post_id,'wpcf-last-name',true);
$registered_to= get_post_meta($post_id,'wpcf-registered-to',true);
$custom_title = $first_name." ".$last_name." ". $registered_to." ";
$updated_data = array(
'ID' => $post_id,
'post_title' => wp_strip_all_tags( $custom_title ),
);
wp_update_post( $updated_data );
} else {
return;
}
}
add_action( 'save_post', 'func_generate_custom_title',30,2);