title: How to get Advanced Custom Fields field key from WordPress database?
body: <p>I’m using Advanced Custom Fields with post-type. I have some select custom fields, and I want to show all the label choices from each field.</p>
  
  <p>I’ve tried this way.</p>
  
  <pre><code>$field = get_field_object('hair_color');
  $hair = $field["choices"];
      foreach($hair as $value){
  </code></pre>
  
  <p>Doing a </p>
  
  <blockquote>
    <p>var_dump($field)</p>
  </blockquote>
  
  <p>it appears empty:</p>
  
  <pre><code>array(18) { 
     ["key"] =&gt; string(16) "field_hair_color" 
     ["label"] =&gt; string(0) "" 
     ["name"] =&gt; string(10) "hair_color" 
     ["_name"] =&gt; string(10) "hair_color" 
     ["type"]=&gt; string(4) "text" 
     ["order_no"]=&gt; int(1) 
     ["instructions"]=&gt; string(0) "" 
     ["required"]=&gt; int(0) 
     ["id"] =&gt; string(20) "acf-field-hair_color" 
     ["class"] =&gt; string(4) "text" 
     ["conditional_logic"] =&gt; array(3) { 
          ["status"] =&gt; int(0) 
          ["allorany"]=&gt; string(3) "all" 
          ["rules"]=&gt; int(0) 
     } 
     ["default_value"] =&gt; string(0) "" 
     ["formatting"] =&gt; string(4) "html" 
     ["maxlength"] =&gt; string(0) "" 
     ["placeholder"] =&gt; string(0) "" 
     ["prepend"] =&gt; string(0) "" 
     ["append"] =&gt; string(0) "" 
     ["value"] =&gt; bool(false) 
  }
  </code></pre>
  
  <p>The only way to get it full is that:</p>
  
  <blockquote>
    <p>get_field_object('field_51ac9d333d704');</p>
  </blockquote>
  
  <pre><code>array(17) { 
     ["key"] =&gt; string(19) "field_51ac9d333d704" 
     ["label"] =&gt; string(13) "Color de pelo" 
     ["name"] =&gt; string(10) "hair_color" 
     ["_name"] =&gt; string(10) "hair_color" 
     ["type"] =&gt; string(6) "select" 
     ["order_no"] =&gt; int(9) 
     ["instructions"] =&gt; string(27) "Selecciona el color de pelo" 
     ["required"] =&gt; int(0) 
     ["id"] =&gt; string(20) "acf-field-hair_color" 
     ["class"] =&gt; string(6) "select" 
     ["conditional_logic"] =&gt; array(3) { 
         ["status"] =&gt; int(0) 
         ["rules"] =&gt; array(1) { 
             [0] =&gt; array(3) { 
                 ["field"] =&gt; string(19) "field_5195ef9879361" 
                 ["operator"] =&gt; string(2) "==" 
                 ["value"] =&gt; string(5) "small" 
             } 
         } 
         ["allorany"] =&gt; string(3) "all" 
     } 
     ["choices"] =&gt; array(5) { 
          ["bald"] =&gt; string(5) "Calvo" 
          ["brown"] =&gt; string(8) "Castaño" 
          ["brunette"] =&gt; string(6) "Moreno" 
          ["red"] =&gt; string(9) "Pelirrojo" 
          ["blonde"] =&gt; string(5) "Rubio" 
      } 
      ["default_value"] =&gt; string(0) "" 
      ["allow_null"] =&gt; int(1) 
      ["multiple"] =&gt; int(0) 
      ["field_group"] =&gt; int(90679) 
      ["value"]=&gt; bool(false) 
  }
  </code></pre>
  
  <p>But I have 3 environment, and I don’t want to hardcode the field key.</p>
  
  <p>Is there any solution?
  Thanks in advance.</p>