WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 10 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
2 years ago

  • Keywords has-screenshots added

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


21 months ago

#3 @schlessera
21 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
10 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.