Skip to content

Instantly share code, notes, and snippets.

@rabidgadfly
Last active February 12, 2016 02:30
Show Gist options
  • Select an option

  • Save rabidgadfly/148d7ad1ccaf52137a56 to your computer and use it in GitHub Desktop.

Select an option

Save rabidgadfly/148d7ad1ccaf52137a56 to your computer and use it in GitHub Desktop.
<?php
//
// Source: http://snippets.khromov.se/dynamically-populating-advanced-custom-fields-values/
//
//Populate the Select field field_5587fccf24f38 with dynamic values
add_filter('acf/load_field/key=field_5587fccf24f38', function($field) {
//These can be dynamically generated using any PHP code
$field['choices']['one'] = 'Choice one';
$field['choices']['two'] = 'Choice two';
return $field;
});
?>
@rabidgadfly
Copy link
Author

Example of populating fields dynamically in ACF using the acf/load_field hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment