WordPress.org

Make WordPress Core

Opened 12 months ago

Closed 8 months ago

Last modified 8 months ago

#24142 closed defect (bug) (invalid)

Zero value for posts_per_page value in wp_query custom instance and for 'Blog pages show at most' option

Reported by: alexvorn2 Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Query Keywords:
Focuses: Cc:

Description

To show no posts if the posts_per_page value is 0.

Currently for custom instances of wp_query, if the value is 0 then this is changed with the value from posts_per_page option from the database. "get_options( 'posts_per_page' )"

For home page if we set value 0 on the settings page, in wp-admin/options-reading.php, after the saves are changed, this value is changed to 1.

I think for both cases if the posts per page value is 0 then no posts should not display.

Change History (5)

comment:1 follow-up: ocean9012 months ago

  • Keywords reporter-feedback close added

What's the use case of having a query which should return 0 results?

comment:2 in reply to: ↑ 1 alexvorn212 months ago

Replying to ocean90:

What's the use case of having a query which should return 0 results?

To hide all posts, for example for a short period of time if the site is under construction...

comment:3 alexvorn212 months ago

  • Keywords needs-docs added; reporter-feedback removed

comment:4 wonderboymusic8 months ago

  • Keywords close needs-docs removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Why would you write a WP_Query by hand that wants zero posts? Why not just comment out the code that displays posts or something

comment:5 DrewAPicture8 months ago

A more valid use case for this might be if you're passing the post_per_page value through absint() or similar and zero gets returned.

I can follow the logic of -1 = unlimited, or 1 = 1, 2 = 2 and so on. So it's odd that we say, "Oh, by the way, 0 doesn't equal 0 here, it actually equals this other thing over there."

It kind of stands to reason that if I pass 0 I'd expect to get 0 results, intentional or not. Just sayin'.

Note: See TracTickets for help on using tickets.