'OR' ); foreach ( $names as $name ) { $meta_query[] = array( 'key' => $name, 'compare' => 'EXISTS', ); } $types = array_values( array_diff( get_post_types(), array( 'revision', 'nav_menu_item', 'customize_changeset' ) ) ); $counts = array( 'posts' => 0, 'links' => 0, 'added' => 0, 'full' => 0, 'dangling' => 0, ); $page = 1; do { $ids = get_posts( array( 'post_type' => $types, 'post_status' => array_merge( array_values( get_post_stati() ), array( 'trash' ) ), 'meta_query' => $meta_query, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query 'fields' => 'ids', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => self::BATCH, 'paged' => $page++, 'no_found_rows' => true, 'update_post_term_cache' => false, ) ); foreach ( $ids as $post_id ) { ++$counts['posts']; foreach ( $names as $name ) { $field = Sync::field_for( $post_id, $name ); if ( ! $field ) { continue; } foreach ( Sync::ids( get_post_meta( $post_id, $name, true ) ) as $related ) { ++$counts['links']; if ( ! get_post( $related ) ) { ++$counts['dangling']; continue; } foreach ( Sync::partners( $field ) as $partner ) { $status = Sync::write( $related, $partner, $post_id, true, $dry ); if ( isset( $counts[ $status ] ) ) { ++$counts[ $status ]; } } } } } $full_batch = count( $ids ) === self::BATCH; } while ( $full_batch ); return $counts; } }