I want to achieve the following -
I have 2 WordPress sites hosted on different servers. Let's call A as sender site and B as receiver site. Whenever I add/update/delete any post in A, it should be reflected as it is in B. Not only post data but the taxonomies and custom fields should also be updated properly in B.
I checked WordPress REST API but I do not prefer it since it just keep a JSON feed on A for which I can send pull request from B. This is fine with posts pulling but not suitable for update and delete. Also, suppose, if today there are 10 blogs, tomorrow there can be 100 blogs and so on. So, as per my understanding it's not best fit for my requirement.
Another approach that I probably looking to go with is adding a functionality in A to send remote request to B and B should have endpoints ready.
E.g. If I create an endpoint at B site say 'update_post' and send request to it from A on a hook. Like on save post action, send a request to 'update_post' endpoint available on B and then B will create post with the post data received from A. The ID of the post would be different in B than A for that post, so I can save the ID got from A in the post meta of the post created in B and then on this relationship basis, handle activities like update, delete etc in future. On update, I also have to take care of postmeta, category/tags, featured image updates.
What I want for now is to create endpoints -
If I create an endpoint like http://example.com/insert_post then I have to create an external PHP file where WordPress functions are not available and I think making use of wp-load.php
to load WordPress isn't a good idea. So, I want to achieve this in WordPress way only.
I researched and found this function http://codex.wordpress.org/Rewrite_API/add_rewrite_endpoint. I also got many articles regarding it but at all the places, I see, they say that we can create endpoint to post, pages, comments etc in json format. I am not sure whether and how it can be helpful in my scenario. I just want this -
- Create a custom endpoint
- Make WordPress functionality available in a proper way
Any help would be greatly appreciated. Thanks in advance !!!