- Joined
- May 14, 2022
- Messages
- 76
- Likes
- 54
- Degree
- 0
I got an issue with the pagination on the category pages I recently modified.
All /category/page/2/ pages show the same content as /category/. Can't figure out why.
To be clear, I do not use /category/ in my URL, but domain/category-topic/.
So domain/category-topic/page/2/ shows the same content as domain.com/category-topic/
I added this code to my functions php to replace the categories with custom pages:
Of course I Googled but I could not find a solution that works. I think it should be something like this:
Anyone an idea?
All /category/page/2/ pages show the same content as /category/. Can't figure out why.
To be clear, I do not use /category/ in my URL, but domain/category-topic/.
So domain/category-topic/page/2/ shows the same content as domain.com/category-topic/
I added this code to my functions php to replace the categories with custom pages:
PHP:
add_filter('request', function(array $query_vars) {
// do nothing in wp-admin
if(is_admin()) {
return $query_vars;
}
// check if the query is for a category archive
if(isset($query_vars['category_name']) && !isset($query_vars['name'])) {
//generate the page path
$pagename = $query_vars['category_name'];
//attempt to load the page matching the $pagename slug
$page = get_page_by_path( $pagename , OBJECT );
if ( isset($page) ){
// completely replace the query with a page query
$query_vars = array('pagename' => "$pagename");
}
}
return $query_vars;
});
Of course I Googled but I could not find a solution that works. I think it should be something like this:
PHP:
add_filter('redirect_canonical','pif_disable_redirect_canonical');
function pif_disable_redirect_canonical($redirect_url) {
if (is_singular()) $redirect_url = false;
return $redirect_url;
}
Anyone an idea?
Last edited: