Home Forums Backend Issues (wp-admin) Dynamically populate a select field’s choices – define defaults


Dynamically populate a select field’s choices – define defaults

  • Hi, referencing this guide – “Dynamically populate a select field’s choices” (ex #2), is there a way within that function to designate choices that are selected by default (either all or some)? Thanks in advance.

  • Yes there is. $field also has the index ‘default_value’


    On fields that allow a single choice return set it to a string.

    $field['default_value'] = 'my value'; Note, this could be for ACF4, at least I set single default values with a string and it works

    for fields that allow multiple choices return an array that holds the list of choices, you can also return an array of one choice for single item fields.

    $field['default_value'] = array (
      'value one' => 'value one',
      'value two' => 'value two',

    Any time you want to know what you can set and what index of $field you need to alter to dynamically load it with a filter the best bet is to create a test field and then use the export feature to see what elements make the $field value. Any of the elements that are exported can be altered by your filter.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.