# Page 2 of Search Results shows homepage

Search bar is just under the header and menu at the top of the page.

Example search: http://www.animefushigi.com/?s=bleach

Scroll down and try going to page 2, see it shows homepage instead.

Similar problem here, but the answer in that question did not work for me

I believe the issue is with my searchform.php.

I have pasted my searchform and search.php here: http://pastebin.com/raw.php?i=rSedK6AC

Any ideas on how to fix this ?

-

I think you are missing the $paged arguments $paged = get_query_var('paged') ? get_query_var('paged') : 1;

-
where does that go –  GreatestSwordsman Mar 19 '12 at 2:39
I believe it should be right above the loop. –  Vijay Sharma Mar 19 '12 at 16:25
another thing Chrome is giving a malware warning about your site. You may want to check it out. –  Vijay Sharma Mar 19 '12 at 16:27
Yes that issue has been handled. And that should go above the loop in which file, the search.php ? –  GreatestSwordsman Mar 20 '12 at 20:44
great... I am glad it worked for you.. –  Vijay Sharma Mar 21 '12 at 21:37

Insert the $paged statement immediately prior to your post query. So something like this: <?php$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$recent = new WP_Query("showposts=10&paged=" .$paged); while($recent->have_posts()) :$recent->the_post();?>

-
Well my index.php does not need paging. But I tried your suggestion, and now the only difference is that it shows page 2 of the homepage instead of page 1. Index.php is not the problem I think. –  GreatestSwordsman Mar 19 '12 at 2:37

This is how I solved it. I needed to recreate the query arguments based on the querystring. I wasn't able to find another way to do it.

Insert the following before the loop.

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_query['posts_per_page'] = get_option( 'posts_per_page' );$search_query['paged'] = $page;$wp_query = new WP_Query( \$search_query );


What I'm essentially doing is pulling down the entire querystring, parsing each key/value pair, and inserting into a new wp_query argument list. I'm also setting the paging parameters of the argument list separately.

-
Ahem … parse_str()? :) –  toscho Nov 16 '12 at 10:15
@toscho good tip, thanks –  anterys Nov 17 '12 at 11:45