Add fictioneer_set_chapter_story_parent()

This commit is contained in:
Tetrakern 2024-10-26 20:46:43 +02:00
parent 713cf7db06
commit a7051df9f1
3 changed files with 24 additions and 21 deletions

View File

@ -62,8 +62,6 @@ function fictioneer_generate_test_comments( $post_id, $number = 3 ) {
*/ */
function fictioneer_generate_test_content() { function fictioneer_generate_test_content() {
global $wpdb;
if ( ! current_user_can( 'manage_options' ) || get_current_user_id() !== 1 || ! WP_DEBUG ) { if ( ! current_user_can( 'manage_options' ) || get_current_user_id() !== 1 || ! WP_DEBUG ) {
return; return;
} }
@ -160,14 +158,7 @@ function fictioneer_generate_test_content() {
fictioneer_generate_test_comments( $chapter_id, $comment_count ); fictioneer_generate_test_comments( $chapter_id, $comment_count );
update_post_meta( $chapter_id, 'fictioneer_chapter_story', $story_id ); update_post_meta( $chapter_id, 'fictioneer_chapter_story', $story_id );
fictioneer_set_chapter_story_parent( $chapter_id, $story_id );
$wpdb->query(
$wpdb->prepare(
"UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID = %d",
$story_id ?: 0,
$chapter_id
)
);
} }
} }

View File

@ -335,7 +335,7 @@ if ( get_option( 'fictioneer_disable_extended_story_list_meta_queries' ) ) {
} }
// ============================================================================= // =============================================================================
// GET CHAPTER STORY ID // CHAPTER STORY ID
// ============================================================================= // =============================================================================
/** /**
@ -351,3 +351,24 @@ if ( get_option( 'fictioneer_disable_extended_story_list_meta_queries' ) ) {
function fictioneer_get_chapter_story_id( $chapter_id ) { function fictioneer_get_chapter_story_id( $chapter_id ) {
return get_post_meta( $chapter_id, 'fictioneer_chapter_story', true ); return get_post_meta( $chapter_id, 'fictioneer_chapter_story', true );
} }
/**
* Sets the chapter parent ID to the story ID
*
* @since 5.26.0
*
* @param int $chapter_id Chapter ID.
* @param int $story_id Story ID.
*/
function fictioneer_set_chapter_story_parent( $chapter_id, $story_id ) {
global $wpdb;
$wpdb->query(
$wpdb->prepare(
"UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID = %d",
$story_id ?: 0,
$chapter_id
)
);
}

View File

@ -3051,19 +3051,10 @@ function fictioneer_save_chapter_metaboxes( $post_id ) {
if ( get_option( 'fictioneer_enable_chapter_appending' ) ) { if ( get_option( 'fictioneer_enable_chapter_appending' ) ) {
fictioneer_append_chapter_to_story( $post_id, $story_id ); fictioneer_append_chapter_to_story( $post_id, $story_id );
} }
global $wpdb;
$wpdb->query(
$wpdb->prepare(
"UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID = %d",
$story_id ?: 0,
$post_id
)
);
} }
} }
fictioneer_set_chapter_story_parent( $post_id, $story_id ?: 0 );
$fields['fictioneer_chapter_story'] = strval( $story_id ?: 0 ); $fields['fictioneer_chapter_story'] = strval( $story_id ?: 0 );
} }