Custom Post Type Quick Edit Issue

Support General Custom Post Type Quick Edit Issue

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #31750
    DragosDragos
    Participant

    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>
    #31751
    DragosDragos
    Participant

    please disregard the div tag on start and end of code

    #31756
    Long NguyenLong Nguyen
    Moderator

    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;
    }
    #31767
    DragosDragos
    Participant

    Hi Long . I tried that but still it returns no title after quick edit or bulk edit.

    #31768
    DragosDragos
    Participant

    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.

    #31776
    Long NguyenLong Nguyen
    Moderator
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.