最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Page 2 of Search Results shows homepage

programmeradmin1浏览0评论

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

Example search: /?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: .php?i=rSedK6AC

Any ideas on how to fix this ?

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

Example search: http://www.animefushigi/?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/raw.php?i=rSedK6AC

Any ideas on how to fix this ?

Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Mar 18, 2012 at 4:15 GreatestSwordsmanGreatestSwordsman 1011 bronze badge
Add a comment  | 

4 Answers 4

Reset to default 1

I think you are missing the $paged arguments

$paged = get_query_var('paged') ? get_query_var('paged') : 1;

Edit your index.php file.
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();?>

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.

It's 2020 and I still had the same issue. Didn't find a solution anywhere; posting it here in case it helps someone else.

I solved the problem by editing .htaccess. In my particular case, this was messing things up:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
发布评论

评论列表(0)

  1. 暂无评论