If I try to add
&posts_per_page=15
to url, it doesn’t work: it won’t change number of post.
I wonder if you’re looking for a custom query variable, e.g. ppp
, to change the number of posts for the main query:
add_filter( 'query_vars', function( $vars )
{
$vars[] = "ppp";
return $vars;
} );
add_action( 'pre_get_posts', function( \WP_Query $q )
{
if( ! is_admin() && $q->is_main_query() )
{
$ppp = $q->get( 'ppp' );
if( ! empty( $ppp ) && 20 >= (int) $ppp )
$q->set( 'posts_per_page', (int) $ppp );
}
} );
where we limit the maximum number of posts to 20. You could then restrict this further if needed.
What am I doing wrong?
The posts_per_page
is a private query variable in the WP
class, so you will not be able to use it as a GET parameter in your request, to modify the main query.
The paged
is a public query variable, so you can access that one.