WordPress.org

Ready to get started?Download WordPress

Forums

Wrong Search Results! (3 posts)

  1. nr2012
    Member
    Posted 2 years ago #

    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: http://www.literaturundkunst.net/wordpress/was-ein-haus-in-sich-selbst-verankert/

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

    thx already

    cheers

  2. marcelle42
    Member
    Posted 2 years ago #

    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
    query_posts($query_args);

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

  3. nr2012
    Member
    Posted 2 years ago #

    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:

    <?php
    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.

    On http://codex.wordpress.org/Creating_a_Search_Page
    it says one has to add this code:

    <?php
    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 '&'.
    Example:
    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:

    query_posts($search_query);

    ($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!

Topic Closed

This topic has been closed to new replies.

About this Topic