I've taken a look at the docs here under "Use on Non-CiviCRM Pages" but I'm coming up empty when trying to access the CRM object via JavaScript.


In functions.php I've tried this:

civicrm_initialize(); $manager = CRM_Core_Resources::singleton(); $manager->addCoreResources(); $manager->addScriptUrl(path-to-ajax.js); // looking around through the available scripts this seemed the obvious candiate

I can get it to load scripts via wp_enqueue_script, but I have no idea which scripts it needs. The docs appear to suggest that it should just magically load everything into the header but that isn't the case for me. The CRM object is never defined.

What I want to do is grab the event list in JSON format.

Any clues? What am I missing?


One way would be to write your own AJAX handler in the usual WordPress way and then grab the event list via the CiviCRM API. Untested pseudocode:

// add AJAX functionality
add_action( 'wp_ajax_my_civi_get_event_data', 'my_civi_get_event_data' );
add_action( 'wp_ajax_nopriv_my_civi_get_event_data', 'my_civi_get_event_data' );

 * Get data from CiviCRM
function my_civi_get_event_data() {
    $civi_data = civicrm_api( 'event', etc etc );
    $data = my_process_civi_data( $civi_data );
    echo json_encode( $data );

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.