I just noticed a new error message on one of my websites' pages that lists posts, http://clubcorvettect.com/category/events/ :

Notice: is_search was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.0.) in /home/wp_gmz28r/clubcorvettect.com/wp-includes/functions.php on line 4138

This site has been running properly for several months. I tried adding code that was suggested in this forum

dd_action('pre_get_posts', function( \WP_Query $q ) {
    if ( ! is_admin() // Only target the front-end
         && $q->is_main_query() // Target the main query
         && $q->is_search() // Target a search query
    ) {
        // do stuff

but it didn't help. Any ideas?

  • 1
    Hi, Welcome to WPSE. Please add the code to your question, without knowing the code it's not really possible to help.
    – Johansson
    May 23, 2017 at 3:29
  • Here's the code that I tried, but it had no effect: add_action('pre_get_posts', function( \WP_Query $q ) { if ( ! is_admin() // Only target the front-end && $q->is_main_query() // Target the main query && $q->is_search() // Target a search query ) { // do stuff } });
    – Mike
    May 24, 2017 at 3:55
  • You are trying to get the query before it's run. What are you trying to achieve? There is always an alternative. Add whatever you are trying to do to your question (using this edit link) and i will write a solution for you if possible.
    – Johansson
    May 24, 2017 at 4:09
  • 1
    I was trying to eliminate the error message and I saw that code was applied in a similar situation. Today, I disabled the WP plug-ins, one at a time, and found that disabling the custom 404 plug-in eliminated the error message. So I applied a simpler 404 page strategy. Problem solved. Thanks for your response, Jack.
    – Mike
    May 25, 2017 at 5:00
  • 1
    You are welcome. You can add your own answer and accept it, to help future visitors.
    – Johansson
    May 25, 2017 at 16:28

1 Answer 1


Hey Mike and welcome to the WordPress Stack Exchange!

First, it's good form to always include the code you use (or a link to where you found it) if you mention it in your post.

This error comes up when you use it prior to the search being run. The WordPress Codex doesn't have a ton of detail, but the basic gist is this: the function is very light weight and only returns a boolean. The reason it must be after the query is because it will always return false as it is checking wp_query() which doesn't exist until a query is run.

Unless your installation is aged and was recently updated, this error has probably been there for a while.

If the site is functioning the way you want, you can find the offending code and remove it since it's not in the right place anyways.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.