carhop__dynamiques-theme__P.../includes/gravity-forms.php
Nonimart 9c05115c9c
All checks were successful
continuous-integration/drone/push Build is passing
FEATURE Handling thematique field population for contribution form
2025-10-21 10:22:11 +02:00

40 lines
895 B
PHP

<?php
add_filter('gform_pre_render', 'populate_taxonomy_terms');
function populate_taxonomy_terms($form)
{
// Specify the form ID and the ID of the select field
$form_id = 2;
$field_id = 15;
// Check if the current form matches the specified form ID
if ($form['id'] == $form_id) {
// Retrieve custom taxonomy terms
$terms = get_terms(array(
'taxonomy' => 'etiquettes',
'hide_empty' => false, // Include empty terms
));
// Prepare choices array for the select field
$choices = array();
foreach ($terms as $term) {
$choices[] = array(
'text' => $term->name,
'value' => $term->term_id,
);
}
// Find the select field by ID
foreach ($form['fields'] as &$field) {
if ($field->id == $field_id) {
// Update choices for the select field
$field->choices = $choices;
break;
}
}
}
return $form;
}