Discussion:
Tax Query Possible Bug
Baki Goxhaj
2013-10-28 21:22:12 UTC
Permalink
I'm running a tax query and I'm getting no results. From debugging I found
[request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND 0 = 1 AND wp_posts.post_type ...
Interestin Part => ... WHERE 1=1 AND 0 = 1 ...
Is this a normal behaviour?

PS: I use the same exact code somewhere else in the site and it works fine.
In this case I'm using this code inside a function in function.php.

Kindly,

Baki Goxhaj
about.me/banago
J.D. Grimes
2013-10-28 21:25:35 UTC
Permalink
Yes, I think this is normal, though it is confusing to lots of developers. The “AND 0=1” is automatically added when a query shouldn’t return any results - at least that is what I remember Nacin saying somewhere, I think.

-J.D.
Post by Baki Goxhaj
I'm running a tax query and I'm getting no results. From debugging I found
[request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND 0 = 1 AND wp_posts.post_type ...
Interestin Part => ... WHERE 1=1 AND 0 = 1 ...
Is this a normal behaviour?
PS: I use the same exact code somewhere else in the site and it works fine.
In this case I'm using this code inside a function in function.php.
Kindly,
Baki Goxhaj
about.me/banago
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Nikola Nikolov
2013-10-28 21:57:30 UTC
Permalink
Are you by any chance trying to run the query before the init hook(or on a
priority before the priority on which your taxonomies are registered) is
run?

That's usually the cause of taxonomy-related issues.
Post by J.D. Grimes
Yes, I think this is normal, though it is confusing to lots of developers.
The “AND 0=1” is automatically added when a query shouldn’t return any
results - at least that is what I remember Nacin saying somewhere, I think.
-J.D.
Post by Baki Goxhaj
I'm running a tax query and I'm getting no results. From debugging I
found
Post by Baki Goxhaj
[request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts
WHERE 1=1 AND 0 = 1 AND wp_posts.post_type ...
Post by Baki Goxhaj
Interestin Part => ... WHERE 1=1 AND 0 = 1 ...
Is this a normal behaviour?
PS: I use the same exact code somewhere else in the site and it works
fine.
Post by Baki Goxhaj
In this case I'm using this code inside a function in function.php.
Kindly,
Baki Goxhaj
about.me/banago
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Baki Goxhaj
2013-10-28 23:48:57 UTC
Permalink
Nikola, that might be the issue. Will try tomorrow and update the thread.
Thanks for the heads up.

Kindly,

Baki Goxhaj
about.me/banago
Post by Nikola Nikolov
Are you by any chance trying to run the query before the init hook(or on a
priority before the priority on which your taxonomies are registered) is
run?
That's usually the cause of taxonomy-related issues.
Post by J.D. Grimes
Yes, I think this is normal, though it is confusing to lots of
developers.
Post by J.D. Grimes
The “AND 0=1” is automatically added when a query shouldn’t return any
results - at least that is what I remember Nacin saying somewhere, I
think.
Post by J.D. Grimes
-J.D.
Post by Baki Goxhaj
I'm running a tax query and I'm getting no results. From debugging I
found
Post by Baki Goxhaj
[request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts
WHERE 1=1 AND 0 = 1 AND wp_posts.post_type ...
Post by Baki Goxhaj
Interestin Part => ... WHERE 1=1 AND 0 = 1 ...
Is this a normal behaviour?
PS: I use the same exact code somewhere else in the site and it works
fine.
Post by Baki Goxhaj
In this case I'm using this code inside a function in function.php.
Kindly,
Baki Goxhaj
about.me/banago
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Baki Goxhaj
2013-10-29 09:54:16 UTC
Permalink
Worked after running the function on the "init" hook. Thanks Nikola.

Kindly,

Baki Goxhaj
about.me/banago
Post by Baki Goxhaj
Nikola, that might be the issue. Will try tomorrow and update the thread.
Thanks for the heads up.
Kindly,
Baki Goxhaj
about.me/banago
Post by Nikola Nikolov
Are you by any chance trying to run the query before the init hook(or on a
priority before the priority on which your taxonomies are registered) is
run?
That's usually the cause of taxonomy-related issues.
Post by J.D. Grimes
Yes, I think this is normal, though it is confusing to lots of
developers.
Post by J.D. Grimes
The “AND 0=1” is automatically added when a query shouldn’t return any
results - at least that is what I remember Nacin saying somewhere, I
think.
Post by J.D. Grimes
-J.D.
Post by Baki Goxhaj
I'm running a tax query and I'm getting no results. From debugging I
found
Post by Baki Goxhaj
[request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts
WHERE 1=1 AND 0 = 1 AND wp_posts.post_type ...
Post by Baki Goxhaj
Interestin Part => ... WHERE 1=1 AND 0 = 1 ...
Is this a normal behaviour?
PS: I use the same exact code somewhere else in the site and it works
fine.
Post by Baki Goxhaj
In this case I'm using this code inside a function in function.php.
Kindly,
Baki Goxhaj
about.me/banago
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Continue reading on narkive:
Loading...