• Resolved MrMister

    (@mrmister)


    Hi everybody,

    I’m designing my own template right now and encountered a very strange problem: Whenever a search request comes up with at least one positive result, the excerpt of every post is being displayed on the search result page. Example:

    When I search for the term “steak” and there is no article on my blog that contains “steak”, it correctly puts out an “not found” string. But when I add a new article that contains the word steak, the search result page suddenly lists the new article along with every other article on my blog.

    I’m not running any search plugins or anything, just the plain wordpress search. Anyone got an idea what the problem might be?
    I added my php files below, maybe you guys see something I don’t. I would really appreciate the help, I don’t really know where to look further.

    Thanks and best whishes,
    MrMister

    [Code moderated as per the Forum Rules. Please use the pastebin]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter MrMister

    (@mrmister)

    Sorry, seems posting code directly here is against forum rules, so I added it on pastebin as suggested.

    http://wordpress.pastebin.ca/1815502
    http://wordpress.pastebin.ca/1815503

    Anyone got an idea? I would really appreciate it… 🙁

    I’d guess it’s this area at fault..

    <?php if(have_posts()): ?>
    					<h2>Suchresultate</h2>
    					<p>Die Suche nach "<span class="searchstring"><?php the_search_query(); ?></span>" ergab folgende Ergebnisse:</p>
    					<?php endif; ?>
    					<?php if(have_posts()): ?><?php query_posts('showposts=10'); ?><?php while(have_posts()):the_post(); ?>

    query_posts should not come after if(have_posts()) ..

    The if( have_posts() ) is to check if “query_posts”(or if not exist, the main query) has posts … it makes no sense that it should come after..

    This query_posts('showposts=10').. causes the query to lose the search terms.

    Review the loop examples.
    http://codex.wordpress.org/The_Loop
    http://codex.wordpress.org/The_Loop_in_Action

    See the default theme’s search.php as an example.

    Thread Starter MrMister

    (@mrmister)

    Hi t31os_,

    thanks for the hint – seems I had a wrong idea of how have_posts and query_posts worked in my head. Fixed it in no time.

    Thank you very much 🙂

    You’re welcome.. 😉

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Search results include EVERY article’ is closed to new replies.