Make WordPress Core

Opened 8 years ago

Last modified 5 years ago

#37530 new defect (bug)

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

Reported by: theinfinity's profile TheInfinity Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.5.3
Component: Query Keywords: has-patch needs-testing needs-unit-tests
Focuses: Cc:

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 8 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 (9)

@dots
8 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
8 years ago

  • Keywords has-patch added

#2 @dots
8 years ago

  • Keywords needs-testing added

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


8 years ago

#4 @swissspidy
8 years ago

  • Keywords needs-unit-tests added

#5 @johnbillion
8 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.


8 years ago

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


8 years ago

#8 @desrosj
5 years ago

  • Milestone set to Future Release

@dots are you able to work on adding unit tests? Here is some documentation to help get started: https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/.

Note: See TracTickets for help on using tickets.