From b2b3a36f57acea63a7531e5a94672b335f602ed1 Mon Sep 17 00:00:00 2001 From: Joe Bailey-Roberts Date: Tue, 16 Nov 2021 15:30:59 +0000 Subject: [PATCH] Update yoast SEO meta migration to include edge cases --- inc/namespace.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/inc/namespace.php b/inc/namespace.php index 36b94a6..2c1d41b 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -590,12 +590,30 @@ function migrate_wpseo_to_yoast() : void { // Handle post meta. $posts_query_args = [ - 'post_type' => 'any', + // Get all post types, even those with exclude_from_search (so "any" is not appropriate https://core.trac.wordpress.org/ticket/17592). + 'post_type' => get_post_types(), 'post_status' => 'any', 'posts_per_page' => 0, - 'meta_key' => '_meta_title', - 'meta_compare' => 'EXISTS', 'fields' => 'ids', + // Ignore filters that may exclude certain post types from queries. + 'suppress_filters' => true, + // phpcs:disable HM.Performance.SlowMetaQuery.dynamic_query -- check required for all of this meta. Performance here isn't a major issue, as this is only run manually on upgrade. + 'meta_query' => [ + 'relation' => 'OR', + [ + 'meta_key' => '_meta_title', + 'meta_compare' => 'EXISTS', + ], + [ + 'meta_key' => '_meta_description', + 'meta_compare' => 'EXISTS', + ], + [ + 'meta_key' => '_meta_keywords', + 'meta_compare' => 'EXISTS', + ], + ], + // phpcs:enable HM.Performance.SlowMetaQuery.dynamic_query ]; $posts = new WP_Query( $posts_query_args );