How to use pre_get_posts to alter posts_per_page of category pages, where ‘posts_per_page’ will be dynamic
If you have pretty permalinks enabled and you visit a category archive, the query var that gets populated is category_name. The cat query var will only be populated after the query is run. So while your code will work in a template, it won’t work in a pre_get_posts action for this reason. To fix this, … Read more