From 72bc6fb6bb90c7e8fcfd7bb6d2118f66279c25aa Mon Sep 17 00:00:00 2001 From: Rasmy Nguyen Date: Tue, 14 Jan 2025 11:09:58 -0500 Subject: [PATCH] fix: remove newspack_corrections_ids meta --- includes/corrections/README.md | 1 - includes/corrections/class-corrections.php | 27 ++++------------------ 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/includes/corrections/README.md b/includes/corrections/README.md index 101094a4df..4330e58ab0 100644 --- a/includes/corrections/README.md +++ b/includes/corrections/README.md @@ -31,4 +31,3 @@ In addition, some correction data is stored in the associated post as post meta: | ------------------------------- | ----------------------- | ----------- | ------------------------------------------------------------- | | `newspack_corrections_active` | `bool` | `post_meta` | Whether the feature is enabled for the post. | | `newspack_corrections_location` | `string` | `post_meta` | Where the correction should be displayed. (`top` or `bottom`) | -| `newspack_corrections_ids` | `array` | `post_meta` | An array of IDs of the corrections associated with the post. | diff --git a/includes/corrections/class-corrections.php b/includes/corrections/class-corrections.php index 3e234a7866..8fb2bf7909 100644 --- a/includes/corrections/class-corrections.php +++ b/includes/corrections/class-corrections.php @@ -31,11 +31,6 @@ class Corrections { */ const CORRECTIONS_LOCATION_META = 'newspack_corrections_location'; - /** - * Meta key for post corrections ids meta. - */ - const CORRECTIONS_IDS_META = 'newspack_corrections_ids'; - /** * Initializes the class. */ @@ -156,10 +151,6 @@ public static function register_post_type() { * @param array $corrections The corrections. */ public static function add_corrections( $post_id, $corrections ) { - $correction_ids = get_post_meta( $post_id, self::CORRECTIONS_IDS_META, true ); - if ( ! is_array( $correction_ids ) ) { - $correction_ids = []; - } foreach ( $corrections as $correction ) { $id = wp_insert_post( [ @@ -177,7 +168,6 @@ public static function add_corrections( $post_id, $corrections ) { $correction_ids[] = $id; } } - update_post_meta( $post_id, self::CORRECTIONS_IDS_META, $correction_ids ); } /** @@ -188,15 +178,14 @@ public static function add_corrections( $post_id, $corrections ) { * @return array The corrections. */ public static function get_corrections( $post_id ) { - $correction_ids = get_post_meta( $post_id, self::CORRECTIONS_IDS_META, true ); - if ( ! is_array( $correction_ids ) ) { - return []; - } return get_posts( [ 'posts_per_page' => -1, 'post_type' => self::POST_TYPE, - 'include' => $correction_ids, + 'meta_key' => self::CORRECTION_POST_ID_META, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key + 'meta_value' => $post_id, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value + 'orderby' => 'date', + 'order' => 'DESC', ] ); } @@ -224,17 +213,9 @@ public static function update_correction( $correction_id, $correction ) { * @param array $correction_ids correction ids. */ public static function delete_corrections( $post_id, $correction_ids ) { - $stored_correction_ids = get_post_meta( $post_id, self::CORRECTIONS_IDS_META, true ); - if ( ! is_array( $stored_correction_ids ) ) { - $stored_correction_ids = []; - } foreach ( $correction_ids as $id ) { wp_delete_post( $id, true ); - if ( isset( $stored_correction_ids[ $id ] ) ) { - unset( $stored_correction_ids[ $id ] ); - } } - update_post_meta( $post_id, self::CORRECTIONS_IDS_META, $stored_correction_ids ); } /**