Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save spivurno/aff119c1a0513421823d30d13fb241cb to your computer and use it in GitHub Desktop.
Save spivurno/aff119c1a0513421823d30d13fb241cb to your computer and use it in GitHub Desktop.
<?php
/**
* Gravity Perks // Populate Anything // Set Post Taxonomy Terms
* http://gravitywiz.com/documentation/gravity-forms-populate-anything/
*/
add_filter( 'gform_after_create_post', function( $post_id, $entry, $form ) {
foreach( $form['fields'] as &$field ) {
if( is_callable( 'gp_populate_anything' ) && $field->{'gppa-choices-enabled'} && $field->{'gppa-choices-object-type'} == 'term' ) {
$value = gp_populate_anything()->get_field_value( $form, $entry, $field->id );
$term_ids = is_array( $value ) ? $value : explode( ',', $value );
$term = get_term( $term_ids[0] );
wp_set_post_terms( $post_id, $term_ids, $term->taxonomy );
}
}
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment