0

My team is attempting to get react-admin working with the WordPress REST API. We need all the standard functionality you'd expect, including filtering, sorting, and associations.

The issue is that the WordPress REST API follows slightly different conventions than the data providers listed in https://marmelab.com/react-admin/DataProviders.html.

An example inconsistency

react-admin expects Header: X-Total-Count

WordPress uses Header: X-WP-Total

Question

Is there a best practice strategy for composing an existing data provider and only slightly tweaking it to work with the WordPress API? For example, mapping the incoming X-WP-Total header to X-Total-Count?

I appreciate any help on solving this problem, and I'll post any updates for future viewers, thank you.

mholubowski
  • 125
  • 9

2 Answers2

0

If anyone else stumbles on this question: I was able to get a connection to the WP-JSON API working with the tutorial code by copying the compiled data provider from ./node_modules/ra-data-json-server/lib/index.js into my project root and changing 4 instances of x-total-count to x-wp-total.

John Ryan
  • 197
  • 2
  • 9
-1

to solve this issue, i have replaced X-WP-Total occurrences by X-Total-Count in WP code base, and it's worked.

Thank you

Alef
  • 9
  • 2
  • It is no good idea to edit the core code directly for after the next wp update your changes will be gone.. – Luckyfella Jun 05 '20 at 22:13
  • i see, but i'm unable to change the WP Headers response !, do you have any idea? – Alef Jun 05 '20 at 22:25
  • I didn‘t try it but you can set your own headers with php header() function or overwrite already set headers. Have a look at the php manual page about header() if you know the total count you should be able to do it – Luckyfella Jun 05 '20 at 22:35