Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spivurno/2364580fe70f322c2c900740b85e832a to your computer and use it in GitHub Desktop.
Save spivurno/2364580fe70f322c2c900740b85e832a to your computer and use it in GitHub Desktop.
<?php
/**
* Gravity Perks // Populate Anything // Populate Post Meta as Choices
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/
*/
// Update "123" with your form ID; Update "4" with your field ID.
add_filter( 'gppa_input_choices_123_4', function( $choices, $field, $objects ) {
$custom_field = str_replace( 'meta_', '', $field['gppa-choices-templates']['label'] );
$meta = get_post_meta( $objects[0]->ID, $custom_field );
$choices = array();
foreach( $meta as $value ) {
$choices[] = array(
'text' => $value,
'value' => $value,
);
}
return $choices;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment