Created
May 17, 2012 15:06
-
-
Save billerickson/2719520 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Main search query | |
if( have_posts() ): | |
while( have_posts() ): the_post(); | |
get_template_part( 'loop', 'search' ); | |
endwhile; | |
// If no results, display random listing | |
else: | |
$args = array( | |
'posts_per_page' => 10, | |
'orderby' => 'rand', | |
); | |
$random = new WP_Query( $args ); | |
if( $random->have_posts() ): | |
echo '<h2>No search results found, but here\'s some posts that might interest you</h2>'; | |
while( $random->have_posts() ): $random->the_post(); | |
get_template_part( 'loop', 'search' ); | |
endwhile; | |
endif; | |
wp_reset_query(); | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment