I use Wordpress with CiviCRM. I would like to create a custom select field and populate the option values with php. After investigating the forum and the documentation I think I should create a hook (or a plugin in wordpress) for that, but not sure.

Could somebody show me a working example or direct me where to continue?

1 Answer 1


The hook you are looking for is hook_civicrm_customFieldOptions. Example from the docs:

function civitest_civicrm_customFieldOptions($fieldID, &$options, $detailedFormat = false ) {
    if ( $fieldID == 1 || $fieldID == 2 ) {
        if ( $detailedFormat ) {
            $options['fake_id_1'] = array( 'id'    => 'fake_id_1',
                                           'value' => 'XXX',
                                           'label' => 'XXX' );
            $options['fake_id_2'] = array( 'id'    => 'fake_id_2',
                                           'value' => 'YYY',
                                           'label' => 'YYY' );
        } else {
            $options['XXX'] = 'XXX';
            $options['YYY'] = 'YYY';
  • Hi, I added a new plugin file for wordpress which contains this function and an add_action. Modified the FieldID in the function to refer to the proper field. I installed Query Monitor for WP to be able to see the hooks and the following hooks are invoked: civicrm_instance_loaded civicrm_initialized civicrm_invoked load-toplevel_page_CiviCRM toplevel_page_CiviCRM 10 CiviCRM_For_WordPress->invoke() Plugin: civicrm admin_print_styles-toplevel_page_CiviCRM admin_print_scripts-toplevel_page_CiviCRM admin_head-toplevel_page_CiviCRM admin_footer-toplevel_page_CiviCRM
    – Csaba
    Jul 2, 2015 at 8:33

Your Answer

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

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