WordPress.org

Make WordPress Core

Opened 22 months ago

Last modified 3 months ago

#21096 new enhancement

Filter on is_front_page return value

Reported by: CoenJacobs Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Query Keywords: dev-feedback
Focuses: Cc:

Description

When you set a page (as 'placeholder' with same slug) as front page which is actually a post type archive to front page, is_front_page() will always return false on that page. The return value of the is_front_page() function is not filterable.

Attached patch adds this filter in the most basic way.

Attachments (1)

is_front_page_filter.diff (652 bytes) - added by CoenJacobs 22 months ago.
Basic filter in place

Download all attachments as: .zip

Change History (6)

CoenJacobs22 months ago

Basic filter in place

comment:1 follow-up: scribu22 months ago

This sounds like a bug in is_front_page(). We should try to fix it, instead of papering over it with a filter.

comment:2 in reply to: ↑ 1 CoenJacobs22 months ago

  • Keywords has-patch removed

Replying to scribu:

This sounds like a bug in is_front_page(). We should try to fix it, instead of papering over it with a filter.

You are right, that will be better. Think the problem is that the page which you set to the front page is no longer a page, but a post type archive. Therefore, this '$this->is_page( get_option( 'page_on_front' ) )' will never return true, since the current page is no page. So maybe this issue is in is_page() instead of this is_front_page() function?

comment:3 mikejolley22 months ago

In our pre_get_posts query where we set the frontpage as the post type archive we have to set some conditionals for it to work:

$q->is_page = false;
$q->is_singular = false;
$q->is_post_type_archive = true;
$q->is_archive = true;

Making is_page true gives us all kinds of errors such as

Notice: Undefined property: stdClass::$ID in /nfs/c08/h03/mnt/125403/domains/woocommerce.faultpress.com/html/wp-includes/query.php on line 3349

Possibly due to the fact we need to unset the page_id to get the post type query working:

$q->set( 'post_type', 'product' );
			$q->set( 'page_id', '' );

Being able to simply set $q->is_front_page = true; would be another workaround (instead of the filter) but agree it would be better to have a fixed is_front_page() function.

comment:4 Mamaduka22 months ago

  • Cc georgemamadashvili@… added

comment:5 nacin3 months ago

  • Component changed from General to Query
  • Milestone changed from Awaiting Review to Future Release

I wouldn't want a filter in a function like this, but open to some other way to manipulate it (or have it simply be correct).

Note: See TracTickets for help on using tickets.