Make WordPress Core

Opened 8 years ago

Last modified 6 years ago

#40166 new defect (bug)

query_vars bug sets is_home to false.

Reported by: avengers's profile avengers Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.3
Component: Query Keywords:
Focuses: Cc:

Description (last modified by SergeyBiryukov)

Hi @boonebgorges, in reference to an older ticket - #25143 following is the issue i am facing.

Similar to the other ticket, when registering a query variable as follows:

<?php
function wppbi_register_query_vars($vars){
        $vars[] = get_option('wppbi_file_url_parameter');
        return $vars;
}
add_filter('query_vars', 'wppbi_register_query_vars');

the is_home variable is set to false when visitng the homepage as such http://yoursite.com/?foo=1 while http://yoursite.com/ works perfectly.

Any solutions are appreciated.

Change History (3)

#1 @SergeyBiryukov
8 years ago

  • Component changed from General to Query
  • Description modified (diff)

#2 follow-up: @indextwo
8 years ago

I'm getting exactly the same behaviour; ended up on ticket #25143 before finding this. Problem described in previous ticket for 3.6 still exists in 4.7.3 and as above: adding a query var via query_vars whilst having a static page set as the homepage results in is_home() incorrectly returning true and is_front_page() returning false when appending a $_GET var to the URL. Remove the query_vars filter, and they behave as expected.

To double-check, I added die('<h1>I AM TEH INDEX</h1>'); to my index.php template (where my page template was normal) and I got the die() rather than the regular page content when add_filter('query_vars', 'my_qv_func') was enabled.

It may be worth noting that this only happens if you add a custom query var:

<?php
function my_qv_func($queryVars) {
        $queryVars[] = 'myqv';
        return $queryVars;
}
add_filter('query_vars', 'my_qv_func'); // Static homepage breaks

Remove the addition (but leave the filter in place) and it behaves as expected:

<?php
function my_qv_func($queryVars) {
        //$queryVars[] = 'myqv';
        return $queryVars;
}
add_filter('query_vars', 'my_qv_func'); // Static homepage behaves as expected

#3 in reply to: ↑ 2 @lllor
6 years ago

The issue is still in WP 5.2

But in order to trigger the issue, you don't have to create a custom query var. Just query the homepage ("/") with one of the default public WP query vars. Example:

http://yoursite.com/?exact

and you will land on the most recent posts page instead of the static page you have set as homepage.

Replying to indextwo:

I'm getting exactly the same behaviour; ended up on ticket #25143 before finding this. Problem described in previous ticket for 3.6 still exists in 4.7.3 and as above: adding a query var via query_vars whilst having a static page set as the homepage results in is_home() incorrectly returning true and is_front_page() returning false when appending a $_GET var to the URL. Remove the query_vars filter, and they behave as expected.

To double-check, I added die('<h1>I AM TEH INDEX</h1>'); to my index.php template (where my page template was normal) and I got the die() rather than the regular page content when add_filter('query_vars', 'my_qv_func') was enabled.

It may be worth noting that this only happens if you add a custom query var:

<?php
function my_qv_func($queryVars) {
        $queryVars[] = 'myqv';
        return $queryVars;
}
add_filter('query_vars', 'my_qv_func'); // Static homepage breaks

Remove the addition (but leave the filter in place) and it behaves as expected:

<?php
function my_qv_func($queryVars) {
        //$queryVars[] = 'myqv';
        return $queryVars;
}
add_filter('query_vars', 'my_qv_func'); // Static homepage behaves as expected
Note: See TracTickets for help on using tickets.