Using this code in the functions.php file to limit the number of results on Search pages and Blog Category pages, yet when viewing /page/2/ etc. for the Blog Category pages, they are throwing a 404.

//For Increasing the number of posts on a search page
function limit_posts_per_archive_page() {
    if ( is_category() )
        $limit = 3;
    elseif ( is_search() )
        $limit = 12;
        $limit = get_option('posts_per_page');

    set_query_var('posts_per_archive_page', $limit);
add_filter('pre_get_posts', 'limit_posts_per_archive_page');

Is there something missing or implemented incorrectly with this?

  • This posts wordpress.stackexchange.com/questions/7009/… can help you. – Chinmoy Kumar Paul Jul 4 '16 at 15:56
  • Interestingly, I've completely removed this code and this code doesn't actually appear to be the problem. Still getting 404 errors on paginated blog category pages (with categories where there are many blog posts, so page 2 does exist,or should). – Michael Cropper Jul 4 '16 at 18:07
  • You will have to trace what is the problem then and update your question. Pagination issues are most often cause by trying to override main query inside template (query_posts() and stuff). – Rarst Jul 4 '16 at 18:25
  • Thanks, will try and get to the bottom of what is overriding this and see what is going on – Michael Cropper Jul 4 '16 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.