Support » Fixing WordPress » Wrong Search Results!

  • Hi there

    When I’m using my wordpress search (with or without activated plugin ‘search everything’) there sure are some correct results displayed,
    BUT there are also posted listed which don’t include the search-term anywhere on the site.

    Even when I go to that link showed in the results and search the source code the search term doesn’t show.

    Why is wordpress showing pages/posts without any clue of the term I entered in the search field?

    I would really be glad if somebody who experienced the same problems or somebody else could give me a hint here.
    I don’t have any clue what the thing is doing… O.o

    (Here the site for testing:

    The site isn’t all ready yet, but the search should work anyway!)

    thx already


Viewing 2 replies - 1 through 2 (of 2 total)
  • Are you using query_posts() at all on search.php? If so, it clears the search term, so you need to add it back in. So:

    $query_args = array('s' => get_query_var('s')); // and whatever other query arguments you need

    Not sure if you still need this information, but I had the issue myself recently, so I’m hoping this helps someone out.

    Hey Marcelle42

    Thanks for the answer. I had not solved the problem, but unfortunately I can’t now either.

    Somehow I’m kinda lost with the code, because it’s already 7 months ago and I have to refresh…

    Until now I just had this code:

    global $wp_query;
    $total_results = $wp_query->found_posts; //contains number of found posts;
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       //what is to show ...
    <?php endwhile;
    wp_reset_query(); ?>

    So no, I haven’t had this.
    But I neither have any query arguments there… O.o
    And I don’t know why.

    it says one has to add this code:

    global $query_string;
    $query_args = explode("&", $query_string);
    $search_query = array();
    foreach($query_args as $key => $string) {
    	$query_split = explode("=", $string);
    	$search_query[$query_split[0]] = urldecode($query_split[1]);
    } // foreach
    $search = new WP_Query($search_query);

    But I don’t understand it.
    Frist it explodes my search-string by the delimiter ‘&’.
    But actually there will never be a ‘&’.
    If I search ‘Mountain’ my query_string is: s=Mountain
    If I search ‘Mountain Lion’ my query_string is: s=Mountain+Lion
    If I search ‘Mountain&Lion’ my query_string is: s=Mountain%26Lion

    so you see there will never be something to seperate by ‘&’.
    Shouldn’t it be

    $query_args = explode("<strong>+</strong>", $query_string);

    then after this code:
    $search_query[$query_split[0]] = urldecode($query_split[1]);
    I’m kind of going back to the first step.
    Because by print_r the array

    print_r ($search_query);

    I get:
    Array ( [s] => Mountain )

    I get from that, that my $search_query is the equivalent of your $query_args, right?
    But since when is ‘s’ an argument for the query?
    I could not find it between all the category_name or author etc.

    Anyway.. then I just would have to put:


    ($search_query should be the equivalent of your $query_args…)

    Well, but that ain’t changing nothing…
    I also do not understand the
    global $wp_query;

    Well I hope somebody can shed some light upon this mess…

    Thanks a lot!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Wrong Search Results!’ is closed to new replies.