Skip to content

Commit 5d4a7ae

Browse files
zippa71spivurno
andauthored
Create gw-set-product-category.php (#566)
* Create gw-set-product-category.php There are several drop down fields. Each subsequent one is filled from the parent by Term_ID using populate anything. In the feed settings, when using this code, you can not specify in which categories the product will be recorded. * Update and rename gravity-forms/gw-set-product-category.php to experimental/gw-gfapc-map-multiple-fields-to-taxonomy.php * Update gw-gfapc-map-multiple-fields-to-taxonomy.php Co-authored-by: David Smith <[email protected]>
1 parent a16989a commit 5d4a7ae

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Gravity Wiz // Gravity Forms // Map Multiple Fields w/ Advanced Post Creation
4+
* https://gravitywiz.com/
5+
*
6+
* By default, the Advanced Post Creation add-on does not allow you to map multiple fields to a taxonomy nor does it
7+
* allow you to set terms by ID.
8+
*
9+
* This snippet allows to specify multiple fields on a form that have been populated with term IDs (we recommend
10+
* [Populate Anything][1] for this) and to set the taxonomy/terms based on those IDs for the generated post.
11+
*
12+
* [1]: https://gravitywiz.com/documentation/gravity-forms-populate-anything/
13+
*/
14+
add_action( 'gform_advancedpostcreation_post_after_creation', function ( $post_id, $feed, $entry, $form ) {
15+
16+
// Update "1", "2", "3" to the field IDs that have been populated with terms. Add additional IDs as needed.
17+
$term_field_ids = array( 1, 2, 3 );
18+
19+
// Update "categories" to the name of the taxonomy to which the populated terms belong.
20+
$taxonomy = 'categories';
21+
22+
$term_ids = array();
23+
foreach ( $term_field_ids as $term_field_id ) {
24+
$term_ids[] = (int) $entry[ $term_field_id ];
25+
}
26+
27+
wp_set_object_terms( $post_id, $term_ids, $taxonomy );
28+
29+
}, 10, 4 );

0 commit comments

Comments
 (0)