Created
April 10, 2019 13:02
-
-
Save spivurno/aff119c1a0513421823d30d13fb241cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
👉 This Gist has been migrated to the Gravity Wiz Snippet Library:
https://github.com/gravitywiz/snippet-library/blob/master/gp-populate-anything/gppa-set-post-taxonomy-terms.php