Comment obtenir la clé de champ Advanced Custom Fields à partir de la base de données WordPress?

Je suis à l'utilisation Avancée des Champs Personnalisés d'après-type. J'ai peu de sélectionner les champs personnalisés, et je veux montrer à tous l'étiquette de choix de chaque champ.

J'ai essayé de cette façon.

$field = get_field_object('hair_color');
$hair = $field["choices"];
    foreach($hair as $value){

Faire un

var_dump($champ)

il apparaît vide:

array(18) { 
   ["key"] => string(16) "field_hair_color" 
   ["label"] => string(0) "" 
   ["name"] => string(10) "hair_color" 
   ["_name"] => string(10) "hair_color" 
   ["type"]=> string(4) "text" 
   ["order_no"]=> int(1) 
   ["instructions"]=> string(0) "" 
   ["required"]=> int(0) 
   ["id"] => string(20) "acf-field-hair_color" 
   ["class"] => string(4) "text" 
   ["conditional_logic"] => array(3) { 
        ["status"] => int(0) 
        ["allorany"]=> string(3) "all" 
        ["rules"]=> int(0) 
   } 
   ["default_value"] => string(0) "" 
   ["formatting"] => string(4) "html" 
   ["maxlength"] => string(0) "" 
   ["placeholder"] => string(0) "" 
   ["prepend"] => string(0) "" 
   ["append"] => string(0) "" 
   ["value"] => bool(false) 
}

Le seul moyen de faire le plein, c'est que:

get_field_object('field_51ac9d333d704');

array(17) { 
["key"] => string(19) "field_51ac9d333d704" 
["label"] => string(13) "Color de pelo" 
["name"] => string(10) "hair_color" 
["_name"] => string(10) "hair_color" 
["type"] => string(6) "select" 
["order_no"] => int(9) 
["instructions"] => string(27) "Selecciona el color de pelo" 
["required"] => int(0) 
["id"] => string(20) "acf-field-hair_color" 
["class"] => string(6) "select" 
["conditional_logic"] => array(3) { 
["status"] => int(0) 
["rules"] => array(1) { 
[0] => array(3) { 
["field"] => string(19) "field_5195ef9879361" 
["operator"] => string(2) "==" 
["value"] => string(5) "small" 
} 
} 
["allorany"] => string(3) "all" 
} 
["choices"] => array(5) { 
["bald"] => string(5) "Calvo" 
["brown"] => string(8) "Castaño" 
["brunette"] => string(6) "Moreno" 
["red"] => string(9) "Pelirrojo" 
["blonde"] => string(5) "Rubio" 
} 
["default_value"] => string(0) "" 
["allow_null"] => int(1) 
["multiple"] => int(0) 
["field_group"] => int(90679) 
["value"]=> bool(false) 
}

Mais j'ai 3 environnement, et je ne veux pas coder en dur le champ clé.

Est-il une solution?
Merci à l'avance.

source d'informationauteur user1432966