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.
Related Posts:
- How to pass posts_per_page and paged params query vars to custom taxonomy archive urls?
- Pagination throws 404 error on custom taxonomy archive pages
- Hierarchical taxonomies in permalink cause 404 for sub term archive
- Custom Taxonomy Archives Page Errors
- Error 404 in Custom taxonomy with pagination
- Custom post type pagination 404 fix?
- Custom Taxonomy Endpoint Pagination using paginate_links()
- Include and Exclude Taxonomies From Archives & Feeds Using ‘pre_get_posts’
- Custom Taxonomy not working with posts_per_page in new WP_query (pagination problem)
- get_query_var(‘paged’) always returns empty
- Check if current term is a child of another term
- Custom Taxonomy Leads to 404 Page – Permalink Structure Flushed
- How to hide custom taxonomy archives same way as hiding custom post types?
- Pagination throws 404
- Page queried instead of a custom taxonomy
- Custom Taxonomy terms with latest post ordered by date pagination issue
- Listing child terms of parent term
- Custom Taxonomy archive returns 404
- Taxonomy page lead to 404 page on pagination
- Using a different template per Custom Taxonomies for single term archive pages
- Remove pagination from WooCommerce product categories on admin edit navigation menus
- Category page for custom-taxonomy shows 404 when using custom permalink structure
- Creating an Archive using a Custom Taxonomy
- Display direct children of the current custom taxonomy in taxonomy.php template
- Date archive permalinks for custom taxonomy
- 404 error- issues with pages after adding custom rules for posts
- Taxonomy archive showing no results
- Dynamic loading of Archive content based on custom taxonomy term name
- List taxonomies according to whether this post is in another taxonomy in taxonomy archive
- orderby meta_value breaks taxonomy term archives
- Why is the custom taxonomy archive page redirecting me to a single post? [closed]
- Pagination on custom taxonomy
- How to have two different versions of a tag/category/taxonomy archive page?
- How to create pagination for custom taxonomy in WordPress
- Automatically Give All Custom Post Types a Pre-Set Category [duplicate]
- How to add Post Format Taxonomy Archive page in the menu?
- Taxonomy Pagination Rewrite
- How does WordPress Parent-Child Taxonomy actually Works?
- Custom taxonomy archive shows 404 error
- Custom Taxonomy index/archive hierarchy
- Filter custom taxonomy archive posts by 2nd custom taxonomy using select dropdown
- Custom Taxonomy Term Archive Page Template that Filters 2 or more Taxonomies
- How to use multiple archive templates for a taxonomy?
- problem in taxonomy-{taxonomy}.php pagination
- Custom post type / taxonomy rewrite archive page 2 gives 404
- Sorting Custom Posts on Archive page with pagination
- Custom post type pagination 404
- Custom taxonomy pagination
- how does the wordpress rest API work
- Problem with wordpress pagination
- Permalink Problems
- How can I change the output display of my pagination?
- How can I get a paginated list of custom taxonomy tags with posts?
- pagination not working on custom-taxonomy template
- Taxonomy archive template that shows posts from more than one taxonomy
- Custom Taxonomy List with Children
- why the archive of custom taxonomy term shows nothing?
- 404 Error on Custom Post Type / Custom Taxonomy
- Can I output a custom taxonomy as a submenu in the site navigation menu?
- Custom taxonomy throw error 404
- Add terms to a taxonomy archive from within the same taxonomy
- Keeping session instance of random display results over pagination breaks
- add pagination in wordpress page template
- Custom Taxonomies Archive Page 404
- problem : Custom taxonomy template not showing
- How to create archive pages for metadata query generated posts (so without taxonomy)?
- How to create a completely functioning separate archive for posts from only 1 or 2 specific categories
- Pagination for Custom Taxonomy
- How to get a terms and posts associated with another term?
- Change the Page Title of the Archive Page for Portfolio Tags
- 404 error next-page [2] PageNavi custom type taxonomy
- pagination for list category posts ( Custom post type )
- Custom taxonomy return 404
- What’s the url queryvar for a taxnomy archive?
- Multi level archive
- index.php Not Showing Custom Posts / Terms
- Custom Taxonomy Archive Page for Parents AND Children?
- Redirect or Prevent Viewing of Custom Taxonomy’s Archives?
- Creating a Taxonomy Page [duplicate]
- Broken paths on taxonomies after changing permalink to post name
- Custom taxonomy rewrite in permalinks for posts gives 404 on pages
- Pagination with custom query (not using posts)
- Exclude 2 in 3 terms of A Taxonomy from all Archives
- Insert code on specific taxonomy archives
- Permalinks not working on MU network with domain mapping
- Custom Taxonomy Archive URL rewrite
- Can you orderby slug in a taxonomy archive page using WP_Query?
- query posts returns 10 records
- More than one Hierarchical Taxonomy and SEO
- Getting Catategory / Taxonomy Description on Non-archive Pages
- add_rewrite_rule pagination 404 error on page 4 and above
- Taxonomies starting with a hyphen (minus) to assign B.C. dates to a post
- Pagination links not working for custom taxonomy
- Custom taxonomy archive empty
- Why my archive title isn’t showing?
- Creating a custom archive page for WooCommerce products based on tags
- taxonomy-{term}.php terms pagination returning 404 after a certain page
- Unwanted redirection to homepage after turning taxonomy to ‘public’=>false
- WordPress /page/2 gives 404 when custom permalinks is set to %category%%postname%
- Infinite Scroll appending Next Product Category Term pages