FEATURE Handling thematique field population for contribution form
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Nonimart 2025-10-21 10:22:11 +02:00
parent c246ee2e6a
commit 9c05115c9c
2 changed files with 40 additions and 0 deletions

View File

@ -14,3 +14,4 @@ require_once(__DIR__ . '/includes/api.php');
require_once(__DIR__ . '/includes/renderPostsDatas.php');
require_once(__DIR__ . '/includes/utilities.php');
require_once(__DIR__ . '/includes/featured-revues.php');
require_once(__DIR__ . '/includes/gravity-forms.php');

View File

@ -0,0 +1,39 @@
<?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;
}