Make WordPress Core

Opened 12 years ago

Last modified 5 years ago

#21096 new enhancement

Filter on is_front_page return value

Reported by: coenjacobs's profile CoenJacobs Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Query Keywords: needs-patch
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 12 years ago.
Basic filter in place

Download all attachments as: .zip

Change History (7)

@CoenJacobs
12 years ago

Basic filter in place

#1 follow-up: @scribu
12 years ago

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

#2 in reply to: ↑ 1 @CoenJacobs
12 years 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?

#3 @mikejolley
12 years 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.

#4 @Mamaduka
12 years ago

  • Cc georgemamadashvili@… added

#5 @nacin
10 years 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).

#6 @swissspidy
9 years ago

  • Keywords needs-patch added; dev-feedback removed
Note: See TracTickets for help on using tickets.