感谢wordpress上的bcworkz。组织机构(https://wordpress.org/support/topic/custom-title-set-on-quick-edit/#post-8631035) 写作:
我不能百分之百确定,但我认为这是因为自定义字段数据没有通过快速编辑在$\\u POST中发送,因此标题最终被设置为空字段。我认为您需要做的是为与标题相关的每个自定义字段添加else代码,当缺少$\\u POST数据时,尝试从POST meta获取数据,如果不存在,请将标题片段设置为某个默认值。完全可选,但您可能会考虑使用“pre\\u post\\u update”操作而不是“post\\u updated”来更改标题。主要优点是,它可以保存额外的查询来保存帖子数据,因为您可以在保存之前更改数据,所以帖子不需要再次保存。>
因此,我为每个标题字段添加了else语句。如果有人试图实现同样的目标,下面是我的新工作代码:
function kida_post_updated_func( $post_id ) {
if ( wp_is_post_revision( $post_id ) || get_post_type($post_id) != \'plot_detail\')return;
remove_action( \'post_updated\', \'kida_post_updated_func\' );
$given = get_post_meta($id, \'wpcf-given\', true);
$givenslug = "given";
$nickname = get_post_meta($id, \'wpcf-nickname\', true);
$nicknameslug = "nickname";
$middle = get_post_meta($id, \'wpcf-middle\', true);
$middleslug ="middle";
$maiden = get_post_meta($id, \'wpcf-maiden-name\', true);
$maidenslug ="maiden-name";
$family = get_post_meta($id, \'wpcf-family\', true);
$familyslug = "family";
if(isset($_POST[\'wpcf\'][$givenslug]) && !empty($_POST[\'wpcf\'][$givenslug])){
$a = $_POST[\'wpcf\'][$givenslug];
}
else {
global $post;
if( empty( $post ) )
$post = get_post($post_id);
if( get_post_type($post_id) !== \'plot_detail\' )
return $post_id;
if( function_exists(\'types_render_field\') ) {
$a = types_render_field( \'given\', array(\'raw\'=>\'true\') );
}
}
if(isset($_POST[\'wpcf\'][$nicknameslug]) && !empty($_POST[\'wpcf\'][$nicknameslug])){
$b = $_POST[\'wpcf\'][$nicknameslug];
$bb = \'"\';
}
else {
global $post;
if( empty( $post ) )
$post = get_post($post_id);
if( get_post_type($post_id) !== \'plot_detail\' )
return $post_id;
if( function_exists(\'types_render_field\') ) {
$bx = types_render_field( \'nickname\', array(\'raw\'=>\'true\') );
if(!empty($bx)) {
$b = $bx;
$bb = \'"\';
}
}
}
if(isset($_POST[\'wpcf\'][$middleslug]) && !empty($_POST[\'wpcf\'][$middleslug])){
$c = $_POST[\'wpcf\'][$middleslug];
}
else {
global $post;
if( empty( $post ) )
$post = get_post($post_id);
if( get_post_type($post_id) !== \'plot_detail\' )
return $post_id;
if( function_exists(\'types_render_field\') ) {
$c = types_render_field( \'middle\', array(\'raw\'=>\'true\') );
}
}
if(isset($_POST[\'wpcf\'][$maidenslug]) && !empty($_POST[\'wpcf\'][$maidenslug])){
$d = $_POST[\'wpcf\'][$maidenslug];
$dd = \'(\';
$de = \')\';
}
else {
global $post;
if( empty( $post ) )
$post = get_post($post_id);
if( get_post_type($post_id) !== \'plot_detail\' )
return $post_id;
if( function_exists(\'types_render_field\') ) {
$dx = types_render_field( \'maiden-name\', array(\'raw\'=>\'true\') );
if(!empty($dx)) {
$d = $dx;
$dd = \'(\';
$de = \')\';
}
}
}
if(isset($_POST[\'wpcf\'][$familyslug]) && !empty($_POST[\'wpcf\'][$familyslug])){
$e = $_POST[\'wpcf\'][$familyslug];
}
else {
global $post;
if( empty( $post ) )
$post = get_post($post_id);
if( get_post_type($post_id) !== \'plot_detail\' )
return $post_id;
if( function_exists(\'types_render_field\') ) {
$e = types_render_field( \'family\', array(\'raw\'=>\'true\') );
}
}
$v = $a . \' \' . $bb . $b . $bb . \' \' . $c . \' \' . $dd . $d . $de . \' \' . $e;
$my_args = array(
\'ID\' => $post_id,
\'post_title\' => $v,
\'post_name\' => sanitize_title($v),
);
// update the post, which calls save_post again
$res = wp_update_post( $my_args, true );
add_action( \'post_updated\', \'kida_post_updated_func\' );
}
add_action( \'post_updated\', \'kida_post_updated_func\' );`