| @@ -90,15 +90,21 @@ | ||
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | // Exclude custom/LPS pages — their SEO is self-managed, so the platform |
| 93 | 93 | // must not treat them as "missing SEO". |
| 94 | - $query_args['meta_query'] = [metasync_get_custom_page_exclusion_meta_query()]; | |
| 94 | + $query_args['metasync_exclude_custom_pages'] = true; | |
| 95 | + add_filter('posts_where', 'metasync_filter_exclude_custom_pages_where', 10, 2); | |
| 95 | 96 | |
| 96 | - $query = new WP_Query($query_args); | |
| 97 | + try { | |
| 98 | + $query = new WP_Query($query_args); | |
| 99 | + } finally { | |
| 100 | + // Remove filters immediately so they don't affect other queries | |
| 101 | + if ($cursor > 0) { | |
| 102 | + remove_filter('posts_where', [__CLASS__, 'filter_where_id_gt'], 10); | |
| 103 | + } | |
| 104 | + remove_filter('posts_where', 'metasync_filter_exclude_custom_pages_where', 10); | |
| 105 | + } | |
| 97 | 106 | |
| 98 | - // Remove the filter immediately so it doesn't affect other queries | |
| 99 | - remove_filter('posts_where', [__CLASS__, 'filter_where_id_gt'], 10); | |
| 100 | - | |
| 101 | 107 | $posts = $query->posts; |
| 102 | 108 | $has_more = count($posts) > $limit; |
| 103 | 109 | |
| 104 | 110 | if ($has_more) { |
| @@ -242,9 +248,9 @@ | ||
| 242 | 248 | 'update_post_term_cache' => false, |
| 243 | 249 | // Exclude custom/LPS pages so the total matches the excluded item list |
| 244 | 250 | // in build() — otherwise the platform sees a count larger than the |
| 245 | 251 | // number of items it can page through. |
| 246 | - 'meta_query' => [metasync_get_custom_page_exclusion_meta_query()], | |
| 252 | + 'metasync_exclude_custom_pages' => true, | |
| 247 | 253 | ]; |
| 248 | 254 | |
| 249 | 255 | if (!empty($modified_after)) { |
| 250 | 256 | $args['date_query'] = [ |
| @@ -255,9 +261,15 @@ | ||
| 255 | 261 | ], |
| 256 | 262 | ]; |
| 257 | 263 | } |
| 258 | 264 | |
| 259 | - $query = new WP_Query($args); | |
| 265 | + add_filter('posts_where', 'metasync_filter_exclude_custom_pages_where', 10, 2); | |
| 266 | + try { | |
| 267 | + $query = new WP_Query($args); | |
| 268 | + } finally { | |
| 269 | + remove_filter('posts_where', 'metasync_filter_exclude_custom_pages_where', 10); | |
| 270 | + } | |
| 271 | + | |
| 260 | 272 | return (int) $query->found_posts; |
| 261 | 273 | } |
| 262 | 274 | |
| 263 | 275 | /** |