How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Get the Default Posts Per Page Value in WordPress
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > How to Get the Default Posts Per Page Value in WordPress
Web Development

How to Get the Default Posts Per Page Value in WordPress

how7o
By how7o
Last updated: May 10, 2026
5 Min Read
WordPress default posts per page — get_option reads the Settings Reading value
SHARE

To read the wordpress default posts per page value — the number the admin set in Settings → Reading — call get_option('posts_per_page'). It comes from the wp_options table, caches on first read, and returns an integer (default 10). Plug it into any custom WP_Query so secondary loops paginate at the same size the rest of the site does.

Contents
  • TL;DR
  • Using it in a custom WP_Query
  • Where WordPress stores it
  • get_option vs get_query_var
  • Overriding for a specific post type
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-04-23 on WordPress 6.5 and PHP 8.3. Originally published 2022-06-27, rewritten and updated 2026-04-23.

TL;DR

$posts_per_page = (int) get_option( 'posts_per_page' );

Using it in a custom WP_Query

$query = new WP_Query( array(
    'post_type'      => 'event',
    'posts_per_page' => (int) get_option( 'posts_per_page' ),
) );

Keeps the custom event loop in sync with whatever the admin set for the blog — change the setting once, it applies everywhere. Hardcoding 10 in the query means the admin’s change silently doesn’t apply to this listing; reading the option is one extra line that future-proofs it.

Where WordPress stores it

The value comes from the wp_options table, row option_name = 'posts_per_page'. The admin sets it in WP Admin → Settings → Reading → “Blog pages show at most”. The default if the setting has never been touched is 10.

get_option() reads wp_options and caches the result for the rest of the request — calling it in a loop is cheap. See ordering posts by meta value and getting posts by date range for WP_Query args that pair well with this one.

wordpress default posts per page — get_option reads wp_options, feeds WP_Query pagination

get_option vs get_query_var

// The admin's global setting
$stored = get_option( 'posts_per_page' );

// The current query's actual limit (after pre_get_posts overrides)
$active = get_query_var( 'posts_per_page' );

Use get_option when you want “the admin setting” as a default for your own queries. Use get_query_var('posts_per_page') when you want to echo “Showing page X of posts with N per page” in the current template — it reflects any pre_get_posts override the theme or a plugin applied.

Overriding for a specific post type

add_action( 'pre_get_posts', 'how7o_events_per_page' );

function how7o_events_per_page( $query ) {
    if ( is_admin() || ! $query->is_main_query() ) {
        return;
    }

    if ( $query->is_post_type_archive( 'event' ) ) {
        $query->set( 'posts_per_page', 20 );
    }
}

Different archive, different page size. The admin’s setting stays at 10 for the blog, but the events archive shows 20 per page. For the scoping-check discipline that keeps this from leaking into other queries see pre_get_posts on custom post types.

Frequently asked questions

What’s the wordpress default posts per page function?

get_option('posts_per_page'). The option comes from Settings → Reading → Blog pages show at most, stored in the wp_options table. Returns an integer; default is 10 if the admin has never touched the setting.

Does this apply to custom post types?

Yes — the single posts_per_page option governs every main-query loop unless a specific template overrides it. WP_Query‘s default posts_per_page argument picks up the same value. Per-post-type limits require a pre_get_posts handler that calls $query->set('posts_per_page', ...) for the relevant archive.

What’s the difference between get_option('posts_per_page') and get_query_var('posts_per_page')?

get_option reads the stored admin setting — always the same for every request. get_query_var('posts_per_page') reads the current query’s effective limit after any overrides (a custom pre_get_posts, a paginate_links override, a WP_Query with an explicit value). Use the option for “the admin said N per page”; use the query var for “how many is this page showing.”

Is it cached?

Yes — WordPress’s options API caches everything it reads. get_option('posts_per_page') hits the database once per request and serves subsequent calls from memory. Calling it repeatedly in a loop is effectively free.

How do I reuse it in a custom WP_Query?

Pass it through: new WP_Query(['post_type' => 'event', 'posts_per_page' => get_option('posts_per_page')]). This keeps the custom loop consistent with the admin’s site-wide preference so the blog and the custom listing paginate at the same size.

Related guides

  • How to Apply pre_get_posts on Custom Post Types in WordPress — overriding the page size per archive.
  • How to Order Posts by Meta Value in WordPress — another WP_Query arg you set alongside posts_per_page.
  • How to Get Posts by Date Range in WordPress — date_query paired with a consistent per-page count.
  • How to Get the Current Category ID in WordPress — context for archive-scoped queries.

References

WordPress developer reference for get_option: developer.wordpress.org/reference/functions/get_option.

TAGGED:phpwordpress

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article WordPress too many redirects HTTPS — Cloudflare flexible SSL loop and the wp-config fix Fix ERR_TOO_MANY_REDIRECTS in WordPress After Switching to HTTPS
Next Article WordPress cron job without a plugin — cron_schedules, wp_schedule_event, and action callback How to Schedule a Cron Job in WordPress Without a Plugin
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Run Laravel queue workers with Supervisor
How to Run Laravel Queue Workers in Production with Supervisor
May 23, 2026
Nginx as a reverse proxy for a Node.js app on Ubuntu
How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
May 23, 2026
Install and configure Redis on Ubuntu for Laravel and WordPress
How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
May 23, 2026
Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth
How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
May 23, 2026
Set up Let's Encrypt SSL with Certbot on Ubuntu
How to Set Up Let’s Encrypt SSL with Certbot on Ubuntu (Apache & Nginx)
May 23, 2026

You Might Also Like

Fix MySQL CONCAT returning NULL with COALESCE or CONCAT_WS
Web Development

How to Handle MySQL CONCAT Returning NULL

4 Min Read
Set a variable in Laravel Blade using the @php directive
Web Development

How to Set a Variable in Laravel Blade Templates (With Examples)

6 Min Read
WordPress custom avatar without a plugin — media uploader writes user meta, get_avatar filter renders the image
Web Development

How to Change a User Profile Picture in WordPress Without a Plugin

10 Min Read
Login to Laravel programmatically without a password (Auth::login and loginUsingId)
Web Development

Login to Laravel Programmatically Without a Password (Auth::login & loginUsingId)

4 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?