Responses to a new request within the template will not work correctly with custom message types.
But the documentation suggests intercepting any request, checking its main request and changing it before execution. This can be done inside the template functions:
function my_post_queries( $query ) { // do not alter the query on wp-admin pages and only alter it if it the main query if (!is_admin() && $query->is_main_query()) { // alter the query for the home and category pages if(is_home()){ $query->set('posts_per_page', 3); } if(is_category()){ $query->set('posts_per_page', 3); } } } add_action( 'pre_get_posts', 'my_post_queries' );
Nikolay Konev
source share