-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Courses page throwing 404 in Hello Elementor theme #7683
Conversation
Test the previous changes of this PR with WordPress Playground. |
Test the previous changes of this PR with WordPress Playground. |
Test the previous changes of this PR with WordPress Playground. |
@Imran92 This seems to work. 🙂 Curious if you tracked down the original PR where this change was introduced to gain an understanding of why it was added in the first place and ensure that we didn't reintroduce a bug? I did some testing based on the original PR and everything seems to work fine. 🤞🏻 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving but I did add a comment.
Hi Donna! Thank you so much for checking the PR and testing for possible unidentified side effects so thoroughly. Yap I did check all the previous relevant PRs. The PR that first introduced this issue was this one actually. I think we just needed the |
Resolves #7678
Proposed Changes
When using the Hello Elementor Theme, our Courses page (/courses-overview) threw a 404.
To explain the reason, we should know that Sensei handles the Courses archive page very differently than usual.
When a request comes to render the Course archive page, we override the usual flow of the request, and handle it using this class. From an archive request, we change it to a single post request, so every plugin or theme after that point considers and handles the request as a single page request. And, as the global single post to be rendered, we set a dummy post, the content of which is whatever we want to render, In this case, a custom content we generate by rendering the blocks from the page from "Settings -> General -> Course Archive Page" setting.
The issue here is not because of the content, but rather, because of the properties of the global wp_query to go with the single post we set. Notice that we set up all the properties to imitate that of a single page,
is_singular
andis_page
is set to true andis_archive
is set to false.Now check out this code in Hello Elementor. This is where it decides which template to choose. Notice that, to render the
single
template, it requires theis_singular
check to be true. But even though we setis_single
, we don't setis_singular
to true. Which causes theis_singular
check to fail. Thus, it falls back to the 404 template. So, settingis_singular
to true fixes the archive rendering issue, and Hello Elementor starts using the single template as we want.Notice that we've also removed
queried_object_id
. It's because once we set "is_singular" to true, this WP Core check also starts passing. So it tries to fetch the dummy post again from the database usingget_post()
using the id from thequeried_object_id
, where it doesn't exist. So it gets a null object, and subsequently throws an error. So I've removed thequeried_object_id
to prevent it from happening.Testing Instructions
Pre-Merge Checklist