WordPress.org

Make WordPress Core

Opened 22 months ago

Last modified 8 months ago

#42947 new defect (bug)

REST API wrong total pages

Reported by: elvishp2006 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9.1
Component: REST API Keywords: has-screenshots
Focuses: rest-api Cc:
PR Number:

Description

When I require posts with the draft status the 'x-wp-total' and 'x-wp-totalpages' headers come with extra values ​​being that not all drafts are from the user making a request, so when I try to pick up the second page the answer comes empty.

https://i.imgur.com/223sEE3.gif

Change History (4)

#1 @elvishp2006
22 months ago

  • Keywords has-screenshots added

This ticket was mentioned in Slack in #core-restapi by schlessera. View the logs.


19 months ago

#3 @schlessera
19 months ago

To make this work, I think WP would need to make two separate queries when checking for draft posts and published posts at the same time.

So, the logic would be:

If status includes draft:

  • remove draft from status and run query
  • run second query for draft status where the author is the current user
  • sum the count of both queries

@timothyblynjacobs mentioned that this might not work as expected due to capability checks, though.

#4 @wongalex
8 months ago

I can take a look at this as my first real bug and get a diff for the above out (assuming, everything functions and it fixes the total pages).

Note: See TracTickets for help on using tickets.