Tell us what you are trying to do?
Autogenerate title from custom field and custom taxonomy name
Is there any documentation that you are following?
I current using a toolset snippet that allows me to autogenerate a post title from two custom fields; however, I am unable to get this working with Custom Field + Custom Category Name
Is there a similar example that we can see?
Not at this time
What is the link to your site? This is a private site
This code works fine
// Neutral Names Autogenerate Post Title
function njea_autogenerate_neutrals_title( $post_id, $post ){
if ( 'neutral' == $post->post_type ) {
$first_name = get_post_meta( $post_id, 'wpcf-first-name', true );
$last_name = get_post_meta( $post_id, 'wpcf-last-name', true );
$new_title = $first_name . " " . $last_name;
$new_title = sanitize_text_field( $new_title );
$new_slug = sanitize_title( $new_title );
$args = array(
'ID' => $post_id,
'post_title' => $new_title,
'post_name' => $new_slug
);
// unhook this function so it doesn't loop infinitely
remove_action('save_post', 'njea_autogenerate_neutrals_title',30,2);
// update the post, which calls save_post again
wp_update_post( $args );
// re-hook this function
add_action('save_post', 'njea_autogenerate_neutrals_title',30,2);
}
}
add_action( 'save_post', 'njea_autogenerate_neutrals_title', 30, 2 );
//
This code does not yet work.
// Evaluation Autogenerate Post Title
function njea_autogenerate_evaluation_title( $post_id, $post ){
if ( 'evaluation' == $post->post_type ) {
$first_name = get_post_meta( $post_id, 'wpcf-local-name', true );
$last_name = get_the_terms( $post_id ) [0]->name;
$new_title = $first_name . " " . $last_name;
$new_title = sanitize_text_field( $new_title );
$new_slug = sanitize_title( $new_title );
$args = array(
'ID' => $post_id,
'post_title' => $new_title,
'post_name' => $new_slug
);
// unhook this function so it doesn't loop infinitely
remove_action('save_post', 'njea_autogenerate_evaluation_title',30,2);
// update the post, which calls save_post again
wp_update_post( $args );
// re-hook this function
add_action('save_post', 'njea_autogenerate_evaluation_title',30,2);
}
}
add_action( 'save_post', 'njea_autogenerate_evaluation_title', 30, 2 );
//