Remove chapter from story if assignment is changed

This commit is contained in:
Tetrakern 2024-08-14 23:01:58 +02:00
parent 45bc835797
commit 2b31d514e4

View File

@ -3022,6 +3022,14 @@ function fictioneer_save_chapter_metaboxes( $post_id ) {
$story_id = absint( $_POST['fictioneer_chapter_story'] );
$current_story_id = absint( get_post_meta( $post_id, 'fictioneer_chapter_story', true ) );
if ( $story_id !== $current_story_id ) {
// Make sure the chapter is not in the list of the wrong story
$other_story_chapters = fictioneer_get_story_chapter_ids( $current_story_id );
$other_story_chapters = array_diff( $other_story_chapters, [ strval( $post_id ) ] );
update_post_meta( $current_story_id, 'fictioneer_story_chapters', $other_story_chapters );
}
if ( $story_id ) {
$story_author_id = get_post_field( 'post_author', $story_id );
$invalid_story = false;