Make WordPress Core

Opened 14 years ago

Closed 12 years ago

#16316 closed enhancement (duplicate)

Enable pagination for the XML-RPC getRecentPosts function

Reported by: feedfabrik's profile feedfabrik Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.1
Component: XML-RPC Keywords: has-patch close
Focuses: Cc:

Description

To retrieve posts via the XML-RPC API, currently the following methods can be called:

  • blogger.getRecentPosts
  • metaWeblog.getRecentPosts
  • mt.getRecentPostTitles

In changeset r16256 these methods were enhanced to support an optional number of posts. However, the query still always starts from the most recent post and there is no way to retrieve older posts without increasing the optional number of posts to a sufficiently large number and retrieving everything before as well. This can place an unnecessary and unwanted burden on the server.

There is an alternative of requesting a post by ID but for this the ID needs to be known in advance. Until ticket #6850 is addressed, there is no way to query for specific IDs.

I would like to suggest an enhancement that leverages r16256 and introduces another optional parameter for offset.

As an example, the code for blogger_getRecentPosts would get an additional:

if ( isset( $args[5] ) )
    $query['offset'] = absint( $args[5] );

That should be enough to get wp_get_recent_posts from post.php do the job.

On more general terms, a new XML-RPC method wp.getPosts could be introduced that simply accepts the array used in wp_get_recent_posts for even more flexibility, but that's probably stuff for another ticket.

Attachments (2)

patch.diff (677 bytes) - added by feedfabrik 13 years ago.
Suggested patch for function mw_getRecentPosts in class-wp-xmlrpc-server.php based on trunk
patch2.diff (1.5 KB) - added by maxcutler 13 years ago.
Extended feedfabrik's patch to include all 3 relevant XML-RPC methods

Download all attachments as: .zip

Change History (17)

#1 @josephscott
14 years ago

  • Cc josephscott added

#2 @redsweater
14 years ago

This has been a major performance/usability challenge for all clients, for years. I've been hoping it would get changed and never thought to propose something as simple as this. It would certainly be a welcome addition.

#3 @redsweater
14 years ago

One other thought: can you do something to expose the feature to clients, i.e. through the wlwmanifest file, or something? We need to know whether we can request an offset-relative get with confidence.

#4 follow-up: @feedfabrik
14 years ago

Any hope of a review here? Is there anything I can do to make this process work? Contribute code in a different form?

I have also started a discussion on http://wordpress.stackexchange.com/questions/7303/how-to-get-all-posts-in-chunks-via-xml-rpc

#5 in reply to: ↑ 4 @ericmann
14 years ago

Replying to feedfabrik:

Is there anything I can do to make this process work? Contribute code in a different form?

If you could contribute a patch, or at least the start of a patch, it would move a lot faster. I had planned to contribute a patch for this already, I just haven't had the time to focus on it.

But if you patch it, it will eventually get reviewed and probably committed to core.

#6 @SergeyBiryukov
13 years ago

  • Keywords needs-patch added

#7 @feedfabrik
13 years ago

Well, it is only the two lines I've already submitted in my ticket 7 months ago. What else do you need as a patch?

@feedfabrik
13 years ago

Suggested patch for function mw_getRecentPosts in class-wp-xmlrpc-server.php based on trunk

#8 @SergeyBiryukov
13 years ago

  • Keywords has-patch added; needs-patch removed

#9 @feedfabrik
13 years ago

  • Cc feedfabrik added

@maxcutler
13 years ago

Extended feedfabrik's patch to include all 3 relevant XML-RPC methods

#10 @maxcutler
13 years ago

  • Cc max@… added

#11 @maxcutler
13 years ago

I've added feedfabrik's changes to the other two mentions mentioned in the original description. nacin pointed out on IRC that technically these API specs don't support an offset parameter, so we'd be breaking those contracts.

Given that the mw.* method implementations already take liberties with the spec by adding WP-specific content_struct fields, I don't have a problem extending it in this way.

The alternative is to wait for #18433 to be polished and committed in 3.4 or later.

#12 @feedfabrik
13 years ago

Thanks, maxcutler. As far as I understand, you're not really breaking the contract by adding to the API. The modified API is a superset of the existing API, so this should be totally transparent.

#13 @westi
13 years ago

I don't think we should be adding an offset to these older APIs I think it is better to encourage clients to switch to the newer WP namespaced api we are working on in #18433 if they want to go further back into the archives.

#14 @markoheijnen
12 years ago

  • Keywords close added

Can be closed since it can be done with the wp.getPosts #18433

#15 @SergeyBiryukov
12 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.