Answers.Body: <p>The hook you are looking for is <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_customFieldOptions" rel="nofollow">hook_civicrm_customFieldOptions</a>. Example from the docs:</p>
  
  <pre><code>function civitest_civicrm_customFieldOptions($fieldID, &amp;$options, $detailedFormat = false ) {
      if ( $fieldID == 1 || $fieldID == 2 ) {
          if ( $detailedFormat ) {
              $options['fake_id_1'] = array( 'id'    =&gt; 'fake_id_1',
                                             'value' =&gt; 'XXX',
                                             'label' =&gt; 'XXX' );
              $options['fake_id_2'] = array( 'id'    =&gt; 'fake_id_2',
                                             'value' =&gt; 'YYY',
                                             'label' =&gt; 'YYY' );
          } else {
              $options['XXX'] = 'XXX';
              $options['YYY'] = 'YYY';
          }
      }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-02T08:33:37.763Z
Answers.Text: 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
Answers.UserDisplayName: Csaba
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-30T14:57:33.587Z
Answers.LastActivityDate: 2015-06-30T14:57:33.587Z
Answers.UserDisplayName: Coleman
Body: <p>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.</p>
  
  <p>Could somebody show me a working example or direct me where to continue?</p>
  
Tags: <wordpress><php>
Title: Creating a custom (select) field and update option values from php
ThreadText: # Creating a custom (select) field and update option values from php
  
  (Asked by: username_0 on 2015-06-30)
  
  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?
  
  **Tags:** wordpress, php
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-06-30. Score: 1
  
  The hook you are looking for is [hook\_civicrm\_customFieldOptions](http://wiki.civicrm.org/confluence/display/CRMDOC/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';
          }
      }
  }
  
  ```
  
  > **Comments:**
  > **username_0**: 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  
  
  ---
  
  