Toolset:. Populate custom field with post title

function tssupp_set_pp_title ( $post_id, $post, $update ) {
  $field_slug = 'practice-point-title';
  $post_type_slug = 'practice-point';
    
  // - bail on wrong post type or on pre-publish auto draft title
  $post_type = get_post_type( $post_id );
  $post_title = get_the_title( $post_id );
  if ( ( $post_type !== $post_type_slug ) || ( $post_title == 'Auto Draft') )  {
    return;
  }
    
  update_post_meta( $post_id, 'wpcf-' . $field_slug, get_the_title( $post_id ) );
}
    
add_action( 'save_post', 'tssupp_set_pp_title', 100, 3);

Visto en https://toolset.com/forums/topic/populate-custom-field-with-post-title/

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Scroll al inicio

We are using cookies on our website

Please confirm, if you accept our tracking cookies. You can also decline the tracking, so you can continue to visit our website without any data sent to third party services.