Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remplir dynamiquement les options d'un champ Sélection (menu déroulant) dans ACF
<?php
// Article/tutoriel complet sur https://mosaika.fr/astuces-developpement-acf/
// Documentation officielle https://www.advancedcustomfields.com/resources/acf-load_field/
/**
* Charger dynamiquement les choix d'un menu déroulant
* Filtre : acf/load_field
*/
function msk_acf_populate_year_field($field) {
$years = [];
$max_years = 5;
for ($i = 0; $i <= $max_years; $i++) {
$date = date('Y') - $i;
$years[$date] = sprintf('Acheté en %d', $date);
}
$field['choices'] = $years;
return $field;
}
add_filter('acf/load_field/name=annonce_date_achat', 'msk_acf_populate_year_field');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.