jeudi 29 janvier 2015

Programmatically change post visibility on save_post action return a 500


I'm trying to change the post visibility for my custom post type. On the edit.php screen the user can use a custom field to set the post type to normal or extended. That field shall work as abstraction for the post_status. However, running the following code inside the save_post action terminates as 500 Internal Server Error:



$options = myplugin_get_options( $post_id );
switch ( $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;
}


Running this code in the load-post.php does work fine. But I just want to set the visibility on saving not every time the post is opened. Any suggestions how to achieve this?


Thanks in Advance!





Aucun commentaire:

Enregistrer un commentaire