I am able to access WordPress functions from outside of a wordpress plugin by doing a require wp-load.php and then I can access (for example) the db functions directly by setting global $wpdb:

require_once( '/mydomain/public_html/wp-load.php' );
global $wpdb;

For CiviCRM I will specifically I need to access the following:

  • Find Contact
  • Add Contact
  • Find Financial Type
  • Add Financical Type
  • Add New Contribution

If I want to access any of these CiviCRM functions (without a plugin), what would I need to add to make them available?


EDIT: I can directly retrieve from database is needed, and I could potentially even add new contact or financial type or contribution direct to database, but if there are functions that do this already then they would the better choice as all the 'checks and balances' will already be there and nothing will get missed.

EDIT: So I see I can use API4 ... the explorer tool is excellent by the way! So how can I access these API4 functions from the same server as CiviCRM, but from seperate php code (not a civicrm function).

2 Answers 2


Start reading here: https://docs.civicrm.org/dev/en/latest/framework/bootstrap/#how-to-bootstrap-civicrm

If running your code with cv is an option for what you're trying to do, like a shell script, then that's the easiest. You just write your script as normal and then cv scr --user=admin myscript.php


You could also access CiviCRM API3 via the WordPress REST API or WP-CLI depending on your use case:

Note that the WP-CLI example should read:

wp civicrm api contact.get first_name=Alice last_name=Roberts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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