Skip to content

Instantly share code, notes, and snippets.

@psaikali
Created March 4, 2018 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psaikali/be6466e2b7d6e6172b45105921bb5533 to your computer and use it in GitHub Desktop.
Save psaikali/be6466e2b7d6e6172b45105921bb5533 to your computer and use it in GitHub Desktop.
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