How7o
  • Home
  • Tools
  • Prank Screens
  • Contact
  • Blog
Reading: How to Get the Default Posts Per Page Value in WordPress
Share
Subscribe Now
How7oHow7o
Font ResizerAa
  • Marketing
  • OS
  • Features
  • Guide
  • Complaint
  • Advertise
Search
  • Home
  • Tools
  • Prank Screens
  • Contact
  • Blog
Follow US
Copyright © 2014-2023 Ruby Theme Ltd. All Rights Reserved.
How7o > Blog > 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.
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

Subscribe Now

Subscribe to our newsletter to get our newest articles instantly!
Most Popular
Display PHP errors — ini_set + php.ini configuration
How to Display PHP Errors
May 10, 2026
PHP convert string to uppercase — strtoupper and mb_strtoupper
How to Convert a String to Uppercase in PHP
May 10, 2026
PHP string to float conversion with cast, regex cleanup, NumberFormatter
How to Convert a String to Float in PHP
May 10, 2026
PHP merge arrays without duplicates — union operator and array_unique
How to Combine Two Arrays Without Duplicates in PHP
May 10, 2026
PHP delete array element — unset, array_splice, array_filter, array_search
How to Delete an Element from a PHP Array
May 10, 2026

You Might Also Like

WooCommerce My Account login form hooks — five positions for injecting content
Web Development

How to Add a Link or Button After the Login Form in WooCommerce

6 Min Read
Find prime numbers in JavaScript thumbnail
Web Development

How to Find Prime Numbers in JavaScript (1 to 100) — Fast & Simple Methods

5 Min Read
MySQL combine columns into string — CONCAT and CONCAT_WS
Web Development

How to Combine Multiple Columns into One String in MySQL

6 Min Read
Laravel Eloquent delete record — trash-bin icon next to User::destroy code snippet
Web Development

How to Delete a Record with Laravel Eloquent (4 Methods)

6 Min Read
How7o

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

Latest News

  • SEO Audit Tool
  • Client ReferralsNew
  • Execution of SEO
  • Reporting Tool

Resouce

  • Google Search Console
  • Google Keyword Planner
  • Google OptimiseHot
  • SEO Spider

Get the Top 10 in Search!

Looking for a trustworthy service to optimize the company website?
Request a Quote
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?