FEATURE Handling thematique field population for contribution form
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
c246ee2e6a
commit
9c05115c9c
|
|
@ -14,3 +14,4 @@ require_once(__DIR__ . '/includes/api.php');
|
||||||
require_once(__DIR__ . '/includes/renderPostsDatas.php');
|
require_once(__DIR__ . '/includes/renderPostsDatas.php');
|
||||||
require_once(__DIR__ . '/includes/utilities.php');
|
require_once(__DIR__ . '/includes/utilities.php');
|
||||||
require_once(__DIR__ . '/includes/featured-revues.php');
|
require_once(__DIR__ . '/includes/featured-revues.php');
|
||||||
|
require_once(__DIR__ . '/includes/gravity-forms.php');
|
||||||
|
|
|
||||||
39
includes/gravity-forms.php
Normal file
39
includes/gravity-forms.php
Normal 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;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user