Custom post title

Toolset: Update Title and Slug of Post with Custom Field Content when post saves in the WordPress backend

add_filter( 'wp_insert_post_data' , 'set_issue_title' , '10', 3 );
  
function set_issue_title( $data , $postarr ) {
if ( 'my_post_type' != $data['post_type'] )
return $data;
  
$post_title = $data['post_title'];
  
if ( ! $post_title ) {
  
$issue_number = trim( $_POST['wpcf']['single1'] ); 
$issue_type = trim( $_POST['wpcf']['single2']);
  
$issue_title = $issue_type . ' - ' . $issue_number;
$post_slug = sanitize_title_with_dashes ($issue_title,'','save');
$post_slugsan = sanitize_title($post_slug);
  
$data['post_title'] = $issue_title;
$data['post_name'] = $post_slugsan;
  }
  
return $data;
}

Visto en https://toolset.com/forums/topic/use-custom-field-to-set-title-slug/

Revisar este otro post: https://toolset.com/forums/topic/use-custom-fields-to-set-post-title-and-post-slug/

Toolset: Update Title and Slug of Post with Custom Field Content when post saves in the WordPress backend Leer más »

Toolset: Auto Generate Post Title and Name/Slug by Combining Other Fields

add_action('cred_save_data', 'build_post_title', 10, 2);
function build_post_title($post_id, $form_data) {
 
if ($form_data['id']==9999) {
$field1 = get_post_meta($post_id, 'wpcf-street_address', true);
$field2 = get_post_meta($post_id, 'wpcf-city_address', true);
$term_list = wp_get_post_terms($post_id, 'state-address', array("fields" => "names"));
$terms = join("-",$term_list);
$field4 = get_post_meta($post_id, 'wpcf-zip_address', true);
 
$post_title=$field1.'-'.$field2.'-'.$terms.'-'.$field4;
$slug = sanitize_title($post_title);
wp_update_post(array('ID'=>$post_id, 'post_title'=>$post_title,'post_name' => $slug));
}
}

Visto en https://toolset.com/forums/topic/auto-generate-post-title-and-nameslug-by-combining-other-fields/

Toolset: Auto Generate Post Title and Name/Slug by Combining Other Fields Leer más »

Scroll al inicio