diff --git a/changelog/fix-archive-404-issue-in-hello-elementor b/changelog/fix-archive-404-issue-in-hello-elementor new file mode 100644 index 0000000000..b1af6ab11b --- /dev/null +++ b/changelog/fix-archive-404-issue-in-hello-elementor @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Hello elementor theme throwing 404 when rendering the Courses archive page diff --git a/includes/unsupported-theme-handlers/class-sensei-unsupported-theme-handler-page-imitator.php b/includes/unsupported-theme-handlers/class-sensei-unsupported-theme-handler-page-imitator.php index 7cf5dbb5f4..6a0dd5f4a9 100644 --- a/includes/unsupported-theme-handlers/class-sensei-unsupported-theme-handler-page-imitator.php +++ b/includes/unsupported-theme-handlers/class-sensei-unsupported-theme-handler-page-imitator.php @@ -87,9 +87,9 @@ protected function output_content_as_page( $content, $object_to_copy = null, $po $wp_query->posts = array( $post ); // On taxonomy pages the queried_object must remain a WP_Term object. if ( ! is_tax() ) { - $wp_query->queried_object = $post; - $wp_query->queried_object_id = $post->ID; + $wp_query->queried_object = $post; } + $wp_the_query = $wp_query; // phpcs:enable WordPress.WP.GlobalVariablesOverride.Prohibited @@ -98,6 +98,7 @@ protected function output_content_as_page( $content, $object_to_copy = null, $po $wp_query->is_404 = false; $wp_query->is_page = true; $wp_query->is_single = true; + $wp_query->is_singular = true; $wp_query->is_archive = false; $wp_query->max_num_pages = 0; diff --git a/tests/unit-tests/unsupported-theme-handlers/test-class-sensei-unsupported-theme-handler-course-archive.php b/tests/unit-tests/unsupported-theme-handlers/test-class-sensei-unsupported-theme-handler-course-archive.php index a445a630bf..3b3f5f06bd 100644 --- a/tests/unit-tests/unsupported-theme-handlers/test-class-sensei-unsupported-theme-handler-course-archive.php +++ b/tests/unit-tests/unsupported-theme-handlers/test-class-sensei-unsupported-theme-handler-course-archive.php @@ -137,6 +137,18 @@ public function testCourseArchivePage_WhenRendered_RendersQueryListBlockIfPageCo $this->assertStringContainsString( 'wp-block-sensei-lms-course-list', $post->post_content ); } + public function testHandleRequest_WhenCalled_SetsGlobalWpQueryWithCorrectIsSingularAndQueryObjectId() { + /* ARRANGE */ + Sensei_Setup_Wizard::instance()->pages->create_pages(); + + /* ACT */ + $this->handler->handle_request(); + + /* ASSERT */ + $this->assertTrue( is_singular() ); + $this->assertEquals( 0, get_queried_object_id() ); + } + /** * Helper to set up the current request to be a course archive page. This request * will be handled by the unsupported theme handler if the theme is not