[wp-trac] [WordPress Trac] #16373: Wrong page loaded requesting custom registered query_vars when correcting is_* for page_on_front requests
WordPress Trac
noreply at wordpress.org
Sat Jan 18 21:57:18 UTC 2014
#16373: Wrong page loaded requesting custom registered query_vars when correcting
is_* for page_on_front requests
-------------------------------------------------+-------------------------
Reporter: jondavis | Owner:
Type: defect (bug) | markjaquith
Priority: high | Status: reopened
Component: Query | Milestone:
Severity: normal | Version: 3.0
Keywords: has-patch 3.3-early needs-unit- | Resolution:
tests |
-------------------------------------------------+-------------------------
Changes (by chipbennett):
* status: closed => reopened
* resolution: invalid =>
Comment:
Reopening, as I found what I believe is a perfectly valid use-case for
registering query variables on the front page, where the query variables
aren't intended to modify the loop query.
While developing a Plugin to allow for front-end modification of Theme
settings, as a Theme options "demo", I ran into this issue. The Plugin
properly registers the query variables, and then sanitizes/validates and
uses them, if set, to filter the front-end-modified Theme settings.
Everything works as expected, unless the front page is set to display a
static page. In that case, when the form is submitted, the page is
refreshed and instead of displaying `page_on_front`, displays the blog
posts index.
If this is too localized, feel free to close again. I just thought it
worthy of consideration. I'm sure there are other, related use cases.
Note, should anyone else encounter this issue, the following work-around
works for me:
{{{
function themeslug_force_static_front_page( $query ) {
if ( $query->is_main_query() ) {
if ( 'page' == get_option( 'show_on_front' ) ) {
if ( '' != get_query_var( 'foobar' ) ) { //
Registered custom query var
$query->set( 'page_id', get_option(
'page_on_front' ) );
$query->is_home = false;
$query->is_page = true;
}
}
}
}
add_action( 'pre_get_posts', 'themeslug_force_static_front_page' );
function themeslug_force_front_page_template( $template ) {
if ( '' != get_query_var( 'foobar' ) ) { // Registered custom
query var
return get_front_page_template();
}
return $template;
}
add_filter( 'template_include', 'themeslug_force_front_page_template' );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/16373#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list