添加 acf 新字段导致我现有功能出错

Adding acf new field causing error with my exisitng function

我正在尝试使用 ACF 创建新字段,但我现有的代码导致了问题,请先查看代码 add_filter('wp_insert_post_data', 'makeNotePrivate', 10, 2);

function makeNotePrivate($data, $postarr)
{

  if((count_user_posts(get_current_user_id(), 'note') > 4) AND !$postarr['ID']) //I'm defining restriction that user not able to create more than 4 note(Note is custom post type)
  {
    die("You have reached your limit ");  
  }
  if($data['post_type'] == 'note')
  {
    $data['post_title'] = sanitize_text_field($data['post_title']);
    $data['post_content'] = sanitize_textarea_field($data['post_content']);
  }
  if($data['post_type'] = 'note' AND $data['post_status']!='trash')
  {
    $data['post_status'] = "private";
  }
  return $data;
}

现在的问题是,当我在 Advance 自定义插件中创建新字段时,它显示“您已达到限制”。这没有任何意义,因为我已经定义了注释类型的条件。

您检查的是第一个条件下的 post 类型。您可以使用以下条件来检查 post 类型:

function makeNotePrivate($data, $postarr)
{

  if((count_user_posts(get_current_user_id(), 'note') > 4) && !$postarr['ID'] && $data['post_type'] == 'note') //I'm defining restriction that user not able to create more than 4 note(Note is custom post type)
  {
    die("You have reached your limit ");  
  }
  if($data['post_type'] == 'note')
  {
    $data['post_title'] = sanitize_text_field($data['post_title']);
    $data['post_content'] = sanitize_textarea_field($data['post_content']);
  }
  if($data['post_type'] = 'note' && $data['post_status']!='trash')
  {
    $data['post_status'] = "private";
  }
  return $data;
}