admin管理员组

文章数量:1289586

i simply dont want to show posts on category page and show the description only, i tried this code but it wont work if i use the zero value, 1+ value would work but not 0

add_filter('pre_get_posts', 'posts_in_category');
function posts_in_category($query){
    if ($query->is_category) {
        if (is_category('')) {
            $query->set('posts_per_archive_page', 0);
        }      
    }
}

i simply dont want to show posts on category page and show the description only, i tried this code but it wont work if i use the zero value, 1+ value would work but not 0

add_filter('pre_get_posts', 'posts_in_category');
function posts_in_category($query){
    if ($query->is_category) {
        if (is_category('')) {
            $query->set('posts_per_archive_page', 0);
        }      
    }
}
Share Improve this question asked Aug 8, 2021 at 19:30 RJMRJM 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Can you change is_category('') to is_category()? Alternatively you can use is_category('category-slug') to hide posts in a single category.

本文标签: functionsHow to Not Show posts on Category page