我正在尝试更改自定义帖子类型的帖子可见性。在“编辑”上。php屏幕用户可以使用自定义字段将帖子类型设置为普通或扩展。该字段应作为post\\U状态的抽象。但是,在save_post action
终止为500 Internal Server Error
:
add_action( \'save_post\', array( $this, \'save_meta_box\' ), 10, 2 );
[...]
public function save_meta_box( $post_id, $post ) {
[...]
if( isset( $_POST[\'options\'] ) ) {
myplugin_set_options( $post_id, $_POST[\'options\'] );
// switch post visibility
switch ( $_POST[\'options\'][\'type\'] ) {
case \'normal\':
wp_update_post( array( \'ID\' => $post_id, \'post_status\' => \'private\' ));
break;
case \'extended\':
wp_update_post( array( \'ID\' => $post_id, \'post_status\' => \'publish\' ));
break;
}
}
在中运行此代码load-post.php
工作正常。但我只想将可见性设置为保存,而不是每次打开帖子时都保存。如何做到这一点,有什么建议吗?提前感谢!