diff --git a/assets/js/sync/components/common/progress-bar.js b/assets/js/sync/components/common/progress-bar.js
index 8bd4ce7d2c..59daabd5d0 100644
--- a/assets/js/sync/components/common/progress-bar.js
+++ b/assets/js/sync/components/common/progress-bar.js
@@ -13,7 +13,7 @@ import { WPElement } from '@wordpress/element';
* @returns {WPElement} Component.
*/
export default ({ isComplete, current, total }) => {
- const now = Math.floor((current / total) * 100);
+ const now = total ? Math.floor((current / total) * 100) : 100;
return (
get_var( "SELECT COUNT(1) AS posts_with_password FROM {$wpdb->posts} WHERE post_password != ''" );
+
+ $post_count -= $posts_with_password;
+ }
+
return $post_count;
}
diff --git a/tests/php/indexables/TestPost.php b/tests/php/indexables/TestPost.php
index f834b1903a..468083be2b 100644
--- a/tests/php/indexables/TestPost.php
+++ b/tests/php/indexables/TestPost.php
@@ -5453,6 +5453,7 @@ public function testQueryDb() {
$post_id_1 = Functions\create_and_sync_post();
$post_id_2 = Functions\create_and_sync_post();
$post_id_3 = Functions\create_and_sync_post();
+ $post_id_4 = Functions\create_and_sync_post( [ 'post_password' => '123' ] );
// Test the first loop of the indexing.
$results = $indexable_post_object->query_db(
@@ -5548,6 +5549,19 @@ public function testQueryDb() {
$this->assertCount( 3, $results['objects'] );
$this->assertEquals( 3, $results['total_objects'] );
+
+ // Test the first loop of the indexing.
+ $results = $indexable_post_object->query_db(
+ [
+ 'per_page' => 1,
+ 'has_password' => null, // `null` here makes WP ignore passwords completely, bringing everything
+ ]
+ );
+
+ $post_ids = wp_list_pluck( $results['objects'], 'ID' );
+ $this->assertEquals( $post_id_4, $post_ids[0] );
+ $this->assertCount( 1, $results['objects'] );
+ $this->assertEquals( 4, $results['total_objects'] );
}
/**