Custom Post Type Quick Edit Issue
- This topic has 5 replies, 2 voices, and was last updated 3 years, 5 months ago by
Long Nguyen.
-
AuthorPosts
-
November 5, 2021 at 3:35 PM #31750
Dragos
ParticipantHi,
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>
November 5, 2021 at 3:38 PM #31751Dragos
Participantplease disregard the div tag on start and end of code
November 5, 2021 at 8:49 PM #31756Long Nguyen
ModeratorHi,
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 theif
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; }
November 6, 2021 at 11:23 AM #31767Dragos
ParticipantHi Long . I tried that but still it returns no title after quick edit or bulk edit.
November 6, 2021 at 11:30 AM #31768Dragos
ParticipantI 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.
November 6, 2021 at 9:18 PM #31776Long Nguyen
ModeratorHi,
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/ -
AuthorPosts
- You must be logged in to reply to this topic.