I want to access WordPress functions from outside WordPress. I have included file wp-load.php in my non-WordPress code.

It is working fine for a single WordPress install, but in my project I have two different WordPress installations - one for the blog and one for resource.

When I try to insert a user in the resource install, it uses the blog install's database because the blog install's wp-load.php is loaded first. Therefore, I am unable to insert users in blog.

Can anyone please tell me how to load both WordPress installations, one by one?

Any help would be appreciated.

  • 1
    instead of including wordpress files, I recommend to use AJAX to get datas of Wordpress : codex.wordpress.org/AJAX_in_Plugins – mmm Apr 25 '16 at 9:48
  • I want to add / update users using wp_insert_user() and wp_update_user(). so it is possible using ajax? – Lalji Nakum Apr 25 '16 at 11:03
  • @mmm I want to add users from outside wordpress. So how it is possible to access wordpress ajax without including wp-load.php? – Lalji Nakum Apr 25 '16 at 11:06
  • in the client website, you can receive and send datas with file_get_contents("http://server/wp-admin/admin-ajax.php?action=AJAXACTION") – mmm Apr 25 '16 at 18:38

I would suggest building your site by either loading one WordPress environment and using the WordPress REST API to communicate with the other, or creating your application completely separate of a WordPress environment and using the REST API to communicate with both (heavily dependent on your specific needs and application. If each request makes heavy use of one installation's functionality, I would imagine it makes more sense to load that installation as the environment to minimize the number of remote HTTP requests incurred).

While the Plugin AJAX approach suggested in the comments could theoretically work it would be something of a hack - AJAX is much more suited to custom interactions between a single front-end and one or more back-ends, and requires that you implement what could end up being a very extensive AJAX back-end yourself (including security mechanisms to prevent potentially malicious unauthorized use and abuse of your functionality).

Meanwhile the REST API is considerably more flexible and inherently suited to remotely accessing core functionality. Custom end-points are arguably easier to implement, and as a result of a different loading procedure REST API requests tend to be about 15% faster than their plugin-AJAX counterparts (both are still much slower than native operations in a loaded environment as both must load some portion of WordPress from scratch for each and every request).

All of that said, I'm not entirely sure why one might need such a division of responsibility between two WordPress installations for a single site - if a performance optimization, I would argue it may be premature and could well end up impairing performance instead of improving it.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.