WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 6 months ago

#37530 new defect (bug)

is_front_page() is based on wrong data -> gives wrong results

Reported by: TheInfinity Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.5.3
Component: Query Keywords: has-patch needs-testing needs-unit-tests
Focuses: Cc:
PR Number:

Description

1) is_front_page() is based on the SQL query, so it always gives back false when you try to use it eg at pre_get_posts. If it has no way to figure it out if it's the front page or not, it should return null instead
2) is_front_page() in themes gives the wrong result false back when you set an static page for the front page and then modify the main query on start page to posts or any other custom post type except page. This forces you to make an additionally SQL query instead of using the main query to build a custom front page.
Both is because of this: https://core.trac.wordpress.org/browser/tags/4.5.3/src/wp-includes/query.php#L4458 . This does not really make sense to get the front page.

Attachments (1)

query.patch (514 bytes) - added by dots 3 years ago.
Now is_front_page() function is working when you set an static page for the front page and then modify the main query on start page to posts or any other custom post type except page.

Download all attachments as: .zip

Change History (8)

@dots
3 years ago

Now is_front_page() function is working when you set an static page for the front page and then modify the main query on start page to posts or any other custom post type except page.

#1 @dots
3 years ago

  • Keywords has-patch added

#2 @dots
3 years ago

  • Keywords needs-testing added

This ticket was mentioned in Slack in #core by sagarmultidots. View the logs.


3 years ago

#4 @swissspidy
3 years ago

  • Keywords needs-unit-tests added

#5 @johnbillion
3 years ago

  • Component changed from General to Query

Thanks for the patch, @dots. This will need unit tests that demonstrate the bug and demonstrate that the fix works as expected.

This ticket was mentioned in Slack in #core by johnbillion. View the logs.


3 years ago

This ticket was mentioned in Slack in #core by mdchiragpatel. View the logs.


3 years ago

Note: See TracTickets for help on using tickets.