我有一个自定义的搜索结果页面,其中的url“/mysearch/location/SUBMITTED DATA/”非常好用。
然而,我现在正在尝试在该页面上进行分页,因此URL将如下所示-“/mysearch/location/SUBMITTED DATA/page/2/”,但当我访问该URL时,我似乎收到的只是“404 page not found”。
我当前的重写使用以下代码执行:
function add_search_store_query_var($vars) {
$vars[] = \'location\';
return $vars;
}
add_filter( \'query_vars\', \'add_search_store_query_var\');
function add_search_store_rewrite_rule() {
add_rewrite_rule(\'mysearch/([^/]+)/([^/]+)$\', \'index.php?page_id=200&location=$matches[1]\', \'top\');
}
add_action(\'init\', \'add_search_store_rewrite_rule\');
以下是我当前分页链接的生成方式:
$total_query = "SELECT COUNT(1) FROM (${query}) AS combined_table";
$total = $wpdb->get_var( $total_query );
$items_per_page = 1;
$page = get_query_var( \'paged\' ) > 1 ? get_query_var(\'paged\') : 1;
$offset = ( $page * $items_per_page ) - $items_per_page;
$searchResults = $wpdb->get_results( $query . " HAVING distance < ".$distance." ORDER BY distance LIMIT ${offset}, ${items_per_page}" );
$paginationOptions = array(
\'base\' => @add_query_arg( \'paged\', \'%#%\' ),
\'format\' => \'\',
\'prev_text\' => __(\'«\'),
\'next_text\' => __(\'»\'),
\'total\' => ceil($total / $items_per_page),
\'current\' => $page,
);
if ( $wp_rewrite->using_permalinks() )
$pagination[\'base\'] = user_trailingslashit( trailingslashit( remove_query_arg( \'s\', get_pagenum_link( 1 ) ) ).\'page/%#%/\', \'paged\' );
if ( ! empty( $wp_query->query_vars[\'s\'] ) )
$pagination[\'add_args\'] = array( \'s\' => get_query_var( \'s\' ) );
如果有人对我如何解决这个问题有任何建议或想法,我们将不胜感激。
谢谢Codarz360