search.php only gets called when no results appear
-
I wrote my own search-function and got some problem now with displaying the results… search.php only gets called, when there are no results to display
When I delete everything in the “if( have_posts() )”-clause, nothing changes when there are posts found… the posts are somehow still showing up (when I delete that part, nothing should show up – i guess). When I delete everything in the “else”-clause, the “Nothing found” message doesn’t appear anymore when no Posts are found.
Here’s my search function ($include_posts contains the IDs of the Posts which match the search criteria):
if(!empty($include_posts)) { $args = array( 'post__in' => $include_posts, 'is_search' => true ); wp_reset_query(); query_posts($args); } else { wp_reset_query(); }
And here’s the code of search.php:
<?php if ( have_posts() ) : ?> <header class="page-header"> <h1 class="page-title"><?php printf( __( 'Suchergebnisse für: %s', 'twentytwelve' ), '<span>' . get_search_query() . '</span>' ); ?></h1> </header> <?php twentytwelve_content_nav( 'nav-above' ); ?> <?php /* Start the Loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content', get_post_format() ); ?> <?php endwhile; ?> <?php twentytwelve_content_nav( 'nav-below' ); ?> <?php else : ?> <article id="post-0" class="post no-results not-found"> <header class="entry-header"> <h1 class="entry-title"><?php _e( 'Keine Suchergebnisse', 'twentytwelve' ); ?></h1> </header> <div class="entry-content"> <p><?php _e( 'Bitte versuchen Sie es erneut mit anderen Suchwörtern.', 'twentytwelve' ); ?></p> <?php get_search_form(); ?> </div><!-- .entry-content --> </article><!-- #post-0 --> <?php endif; ?>
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘search.php only gets called when no results appear’ is closed to new replies.