I have a custom query to display random posts in my sidebar like this:
$newQuery = array(
'post__in' => get_option('sticky_posts'),
'post_type' => 'ad_listing',
'posts_per_page' => 10,
'orderby' => 'rand',
'post_status' => 'publish');
// Get new set of ads
$smStickyPosts = new WP_Query($newQuery);
if ($smStickyPosts->have_posts()) : while($smStickyPosts->have_posts() : $smStickyPosts->the_post();
//Display posts
endwhile;
This works fine in all pages, except on the search page, for some reason the first post on the list is always the post that coincides with the search term (for example, if I search for foo and I have a post with the title "foo" it will show first followed by 9 random posts), it's like the search term is getting passed to the custom loop as well.
Also I noticed that if I search for something that doesn't find any results the posts are always the same, it's like the orderby => rand is not doing anything, it works fine on the rest of the site though.
Does anyone know what could be wrong?
Thanks in advance.