I have two WordPress websites - Alpha and Beta. I have 3 sections on the Alpha site that display content from the Beta site using WordPress Rest API:
- Section 1 displays latest posts from the Beta site.
- Section 2 displays posts from category one from the Beta site.
- Section 3 displays posts from category two from the Beta site.
Right now I'm using wp_remote_get to make REST API calls to the Beta site. Since PHP is a sequential language, the page load halts for a few seconds because it waits for all API calls complete before moving forward.
I was able to get around this issue by using WordPress Transients on Alpha to cache data I get from the Beta Site. But when the transient expires, page load halt thing happens again on the first page load.
I want load posts from the Beta site on the Alpha site asynchronously. I was trying to do it using AJAX but I'm unable to figure out how.
Edit: I have PHP function that renders HTML for post section. I'm trying to figure how do get data from the Beta site using jQuery/Ajax and pass it my PHP function so that it could render it.