Support Forum
Hi,
For my custom post type, I set title auto generated by the metabox fields. Everything works fine after saving the post the title is generated by metabox field but its not working if I do quick edit or bulk edit. It will show no title after bulk update or quick update. It only works if I open the single post and update it there.
Here is my code.
<div>function set_leasing_meta_title( $data , $postarr ) {
if($data['post_type'] == 'leasing') {
if($_POST['type_of_leasing'] == 'Shop Spaces') {
$title = $_POST['shop_station'] . ' ' . $_POST['shop_unit'];
} else {
$title = $_POST['event_station'] . ' ' . $_POST['event_unit'];
}
$post_slug = sanitize_title_with_dashes ($title,'','save');
$post_slugsan = sanitize_title($post_slug);
$data['post_title'] = $title;
$data['post_name'] = $post_slugsan;
}
return $data;
}
add_filter( 'wp_insert_post_data' , 'set_leasing_meta_title' , '500', 2 );</div>
please disregard the div tag on start and end of code
Hi,
Because in the Quick Edit mode or Bulk Edit, the global variable $_POST
does not store any value. You can move the variable $data
inside the if
condition to make sure the global variable stores value. For example:
function set_leasing_meta_title( $data , $postarr ) {
if($data['post_type'] == 'leasing') {
if($_POST['type_of_leasing'] == 'Shop Spaces') {
$title = $_POST['shop_station'] . ' ' . $_POST['shop_unit'];
$post_slug = sanitize_title_with_dashes ($title,'','save');
$post_slugsan = sanitize_title($post_slug);
$data['post_title'] = $title;
$data['post_name'] = $post_slugsan;
}
}
return $data;
}
Hi Long . I tried that but still it returns no title after quick edit or bulk edit.
I tried using this get_post_meta insted of $_POST. when I quick edit it returns the correct title but the problem is I need to uodate it twice to generate the correct title.
Hi,
You can follow these topics to update the post title by custom field value with the meta box hook rwmb_{$meta_box_id}_after_save_post
https://support.metabox.io/topic/adding-metabox-field-data-to-the-post-title/
https://support.metabox.io/topic/trying-to-set-title-from-field-in-cpt-from-the-custom-fields/