Make WordPress Core

Opened 10 years ago

Closed 9 years ago

#2558 closed enhancement (fixed)

query_posts() should support offset

Reported by: markjaquith Owned by: markjaquith
Milestone: 2.1 Priority: normal
Severity: normal Version: 2.1
Component: General Keywords: has-patch 2nd-opinion
Focuses: Cc:


query_posts() doesn't support "offset," which is hugely annoying. You have to resort to posts_per_page=5&paged=2 to see posts 6-10, for example.

Attachments (1)

query_posts_offset_support.diff (2.0 KB) - added by markjaquith 9 years ago.
Support for 'offset' when querying posts (/trunk/)

Download all attachments as: .zip

Change History (3)

9 years ago

Support for 'offset' when querying posts (/trunk/)

#1 @markjaquith
9 years ago

  • Component changed from Administration to General
  • Keywords has-patch 2nd-opinion added
  • Owner changed from anonymous to markjaquith
  • Severity changed from normal to enhancement
  • Status changed from new to assigned
  • Version changed from 2.0.1 to 2.1

Try this patch out. It adds a new (private) query var: 'offset'

Offset moves the starting post by the specified number of posts.

e.g., 'offset=2' would start with third post (2 posts offset from the first post). This is how it works in Movable Type.

You can use this to specify a range of posts that was not previously possible.

e.g. 'offset=2&posts_per_page=10'

Previously, you would have had to query the first 12 posts and used PHP to ignore the first two. This is much cleaner, more efficient, and easy for people to understand.

#2 @ryan
9 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [3867]) Add offset support to query_posts(). Props Mark Jaquith. fixes #2558

Note: See TracTickets for help on using tickets.