Lỗi 404:
Khi nhảy đến trang 2 có báo lỗi 404 không tìm thấy, nếu gặp lỗi này bạn nên kiểm tra lại hook pre_get_posts.
Giải pháp:
*Chỉnh lại prep_get_posts:
function my_post_queries( $query ) {
// do not alter the query on wp-admin pages and only alter it if it's the main query
if ($query->is_main_query()){
// alter the query for the home and category pages
if(is_home()){
//$query->set('posts_per_page', 5);
if(!$query->get('post_type')){
$query->set('post_type',array(tutorial_posttype,'post'));
}
}
}
}
|
Ví dụ vì nguyên nhân nào đó không xác định post_type thì bạn thiết lập lại post_type.
* Có thể thay thế page vs paged:
function remove_page_from_query_string($query_string)
{
if (isset($query_string['name']) && $query_string['name'] == 'page' && isset($query_string['page'])) {
unset($query_string['name']);
// 'page' in the query_string looks like '/2', so i'm spliting it out
list($delim, $page_index) = split('/', $query_string['page']);
$query_string['paged'] = $page_index;
}
return $query_string;
}
// I will kill you if you remove this. I died two days for this line
add_filter('request', 'remove_page_from_query_string');
|
Hoặc thêm dòng sau:
function bti_change_posts_per_page(){ return 1; }
if( preg_match("|\/".get_option('tag_base')."\/.+\/page\/[0-9]+$|i", $_SERVER['REQUEST_URI']) ){
add_filter( 'pre_option_posts_per_page' , 'bti_change_posts_per_page');
}
|
Unregistered version