This demo runs the code snippets on a live WordPress running in the browser via WASM. Full source code available at https://github.com/adamziel/wordpress-wasm
See also an interactive WordPress instance and code editor .
To fetch the list of pages, we will use the getEntityRecords selector. In broad strokes, it will issue the correct API request, cache the results, and return the list of the records we need. Here’s how to use it:
... Loading – it may take a while ...Once you run that code, you will see it returns null. Why? The pages are only requested by the getEntityRecords resolver after first running the selector. If you wait a moment and re-run it, it will return the list of all pages.
Here's how you can use the getEntityRecords to render a list of pages:
... Loading – it may take a while ...