The gform_advancedpostcreation_taxonomy_mapping_field filter allows users to modify which field is used when looking up terms via get_term_by()
. Defaults to name
, but can be any of: ‘slug’, ‘name’, ‘term_id’ (or ‘id’, ‘ID’), or ‘term_taxonomy_id’.
Usage
A generic example of how to use the filter:
add_filter('gform_advancedpostcreation_taxonomy_mapping_field', 'your_custom_function', 10, 2); function your_custom_function($field, $taxonomy) { // your custom code here return $field; }
Parameters
$field
(string) – Current form field that is being processed for mapping.$taxonomy
(string) – Taxonomy currently being mapped to, i.e., ‘category’.
More information
See Gravity Forms Docs: gform_advancedpostcreation_taxonomy_mapping_field
Examples
Assign Taxonomy based on Term ID
Use the term_id
instead of name
to assign the taxonomy.
add_filter('gform_advancedpostcreation_taxonomy_mapping_field', function($field, $taxonomy) { return 'term_id'; // can also use 'id' or 'ID' }, 10, 2);
Assign Taxonomy based on Slug
Use the slug
instead of name
to assign the taxonomy.
add_filter('gform_advancedpostcreation_taxonomy_mapping_field', function($field, $taxonomy) { return 'slug'; }, 10, 2);
Conditional Field Mapping based on Taxonomy
Conditionally choose which field to use for mapping based on the taxonomy.
add_filter('gform_advancedpostcreation_taxonomy_mapping_field', function($field, $taxonomy) { if ($taxonomy !== 'category') { return $field; } return 'term_id'; }, 10, 2);
This code can be placed in the functions.php
file of the active theme, a custom functions plugin, or a custom add-on.