我已經搜索了高和低的解決方案,並嘗試了不同的,包括徹底解釋Chip Bennett here一個,但我仍然似乎無法得到它的工作。WordPress的:搜索結果分頁仍然不起作用
結果的第一頁正常工作,但從頁面2它只顯示索引模板,仍然說沒有找到頁面。這裏是我的代碼:
的functions.php
function advanced_search_query($query) {
if ($query->is_search) {
$query->set('s', $_GET['s']);
$query->set('post_type', array('properties'));
$query->set('meta_key', $_GET['meta_key']);
$query->set('orderby', $_GET['sortby']);
$query->set('order', $_GET['order']);
$query->set('posts_per_page', '5');
$query->set('paged', $paged);
if (isset($_GET['author'])) {
$query->set('author', $_GET['author']);
}
if (isset($_GET['propertytype'])) {
$query->set('taxonomy', 'propertytype');
$query->set('terms', $_GET['propertytype']);
}
$minCost = $_GET['minCost'];
$minCost = preg_replace("/[^0-9]/","", $minCost);
if ($minCost == ""){
$minCost = "0";
}
$maxCost = $_GET['maxCost'];
$maxCost = preg_replace("/[^0-9]/","", $maxCost);
if ($maxCost == ""){
$maxCost = "99999999999999";
}
$query->set('meta_query', array(
'relation' => 'AND',
array(
'key' => 'ce_location',
'value' => $_GET['location'],
'compare' => 'LIKE',
'type' => 'CHAR'
),
array(
'key' => 'ce_cost',
'value' => array($minCost, $maxCost),
'compare' => 'BETWEEN',
'type' => 'NUMERIC'
),
array(
'key' => 'ce_bedrooms',
'value' => array($_GET['minBedrooms'], $_GET['maxBedrooms']),
'compare' => 'BETWEEN',
'type' => 'NUMERIC'
),
array(
'key' => 'ce_tenancy',
'value' => $_GET['tenancy'],
'compare' => 'LIKE',
'type' => 'CHAR'
)
));
};
return $query;
};
add_filter('pre_get_posts', 'advanced_search_query', 1000);
代碼拉查詢參數
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]);
}
$search_query['paged'] = get_query_var('paged') ? get_query_var('paged') : 1;
$search = new WP_Query($search_query);
循環代碼:
if (have_posts()) : while (have_posts()) : the_post();
//loop content
endwhile;
if(function_exists('wp_simple_pagination')) { wp_simple_pagination(); } ?>
else :
echo 'Sorry, there are currently no property listings available';
endif;
任何建議將非常感激。
編輯:
我也注意到,當我嘗試訪問頁面的URL被修改2
這是第1頁網址:
http://localhost/cunningham/?location=&propertytype=&minBedrooms=1&maxBedrooms=9&minCost=0&maxCost=100000&meta_key=&tenancy=&s=
第2頁網址:
http://localhost/cunningham/page/2/?location&propertytype&minBedrooms=1&maxBedrooms=9&minCost=0&maxCost=100000&meta_key&tenancy&s/