title: Correct Way to Output ACF Generated Values Using WP_Query() and Foreach()
body: <p>I have setup fields and sub-fields using Advanced Custom Fields (ACF). The structure is similar to:</p>
  
  <pre><code>Field: Pet Details
  - Sub-Field: Pet Name (text)
  - Sub-Field: Pet Birthday (date picker)
  - Sub-Field: Pet Gender (taxonomy, select)
  - Additional... 
  </code></pre>
  
  <p>I have been able to use these within my custom post type (/cpt_slug/post_title) using the <code>get_field()</code>, <code>get_sub_field()</code> functions, however I have not been able to usilise the default ACF functions ( <code>get_field()</code>, <code>get_sub_field()</code>, etc ) in conjunction with additional pages where this information is being displayed - in this case, <code>domain.com/account</code> (woocommerce my account page) which is fine as I'm happy to use <code>WP_Query</code>.</p>
  
  <p>While I have a working code below, it requires me to setup <code>$variable = get_post_meta( $pet-&gt;ID, field_sub_field, true )</code> for each acf sub_field. Given the array structure, </p>
  
  <p>The best result I could come up with was <code>echo $details['pet_details_pet_name'][0]</code> which outputs 'Cooper' (correct), but with my limited knowledge of arrays, is there any chance that the '0' will ever become a '1' and not allow this to work? I don't believe that the cpt/acf will ever put a second value in the array but I would like to hear your thoughts.</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>global $current_user;
  
  $query = new WP_Query ( array ( 
      'post_type' =&gt; 'audp_pets', 
      'author' =&gt; $current_user-&gt;ID, 
      'order' =&gt; 'ASC' 
      ) );
  
  $pets = $query-&gt;posts;
  
  if ( $pets ) {
  
      foreach ( $pets as $pet ) {
  
          var_dump ( $pet );
  
          ?&gt;&lt;hr&gt;&lt;?php
  
          echo "\$pet-&gt;post_title = " . $pet-&gt;post_title . '&lt;br /&gt;';
  
          ?&gt;&lt;hr&gt;&lt;?php
  
          $details = get_post_meta( $pet-&gt;ID );
  
          $pet_name = get_post_meta( $pet-&gt;ID, 'pet_details_pet_name', true );
          echo "\$pet_name = " . $pet_name . '&lt;br /&gt;';
  
          ?&gt;&lt;hr&gt;&lt;?php
  
          var_dump ( $details );
  
  
      }
  
  wp_reset_postdata();
  
  }
  </code></pre>
  
  <p><strong>Outputs (Source)</strong></p>
  
  <pre><code>object(WP_Post)#13185 (24) {
    ["ID"]=&gt;
    int(952)
    ["post_author"]=&gt;
    string(1) "1"
    ["post_date"]=&gt;
    string(19) "2020-01-16 16:24:17"
    ["post_date_gmt"]=&gt;
    string(19) "2020-01-16 05:24:17"
    ["post_content"]=&gt;
    string(0) ""
    ["post_title"]=&gt;
    string(6) "AA0AA0"
    ["post_excerpt"]=&gt;
    string(0) ""
    ... (additional fields)
  }
  
  (N.B -- $pet-&gt;post_title = AA0AA0)
  
  array(56) {
    ["_edit_last"]=&gt;
    array(1) {
      [0]=&gt;
      string(1) "1"
    }
    ["_edit_lock"]=&gt;
    array(1) {
      [0]=&gt;
      string(12) "1579152259:1"
    }
    ["pet_details_pet_name"]=&gt;
    array(1) {
      [0]=&gt;
      string(6) "Cooper"
    }
    ["_pet_details_pet_name"]=&gt;
    array(1) {
      [0]=&gt;
      string(19) "field_5e1189ab705b2"
    }
    ["pet_details_pet_birthday"]=&gt;
    array(1) {
      [0]=&gt;
      string(8) "20130313"
    }
    ... (additional fields)
  }
  
  (N.B. $pet_name = Cooper)
  </code></pre>
  
  <p>Thank-you in advance.</p>