使用ACF创建新的自定义帖子类型时更新帖子标题

时间:2019-09-25 10:14:11

标签: wordpress advanced-custom-fields

我已经从Wordpress中的特定“自定义帖子类型”中删除了默认的“标题”字段。但是在发布表上,它显示为(no title)。显然:P

我想做的是使用ACF字段作为标题。此刻,我是这样做的

function my_acf_update_value( $value, $post_id, $field ) {
    global $_POST;

    $new_title = get_field('username', $post_id);
    $new_slug = sanitize_title( $new_title );

    $my_post = array(
      'ID'           => $post_id,
      'post_title' => $new_title,
      'post_name' => $new_slug
    );

    // Update the post into the database
  wp_update_post( $my_post );
  return $value;
}

add_filter('acf/update_value/name=username', 'my_acf_update_value', 10, 3);

问题在于它仅在更新自定义帖子类型时有效,而在创建自定义帖子类型时不起作用。我无法在ACF文档中找到合适的过滤器。有想法吗?

0 个答案:

没有答案
相关问题