Created
March 4, 2018 15:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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