这是我的自定义帖子类型代码,一切正常,但当我发布帖子时,帖子将以草稿模式保存。
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => array(\'slug\' => $slug),
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => false,
\'menu_position\' => 4,
\'supports\' => $supports,
\'taxonomies\' => array( \'category\' ),
);
register_post_type(self::$PostTypeName, $args);
最合适的回答,由SO网友:Akhilesh29989 整理而成
使用“wp\\u insert\\u post\\u data”筛选器挂钩解决此类问题
add_filter(\'wp_insert_post_data\', \'filter_post_data\', 99, 2);
function filter_post_data($postData, $postarr) {
if ($postData[\'post_status\'] == \'draft\') {
$postData[\'post_status\'] = \'publish\';
}
return $postData;
}