How to display ACF field data in the WP_Query loop

If you are using the ACF integration on the you will likely need to display the Vimeo Selection/Upload field’s data on the front-end.

Querying the field’s data in the loop

$query = new WP_Query([
    'post_type'      => 'post',
    'post_status'    => 'publish',
    'posts_per_page' => 6,
]);

while ($query->have_posts()) {
    $query->the_post();
    $data = get_field('vimeo_video'); // vimeo_video is the ACF field key
    $additional = get_post_meta(get_the_ID(), '_vimeo_video_data', true); // Cached data.
    echo '<pre>';
    var_dump($data);
    var_dump($additional);
    echo '</pre>';
}

The above code outputs something like this:

string(17) "/videos/XXXXXXXXX"
array(1) {
  [XXXXXXXXX]=>
  array(9) {
    ["name"]=>
    string(11) "Nice View"
    ["description"]=>
    string(17) "Some description"
    ["link"]=>
    string(27) "https://vimeo.com/XXXXXXXXX"
    ["player_embed_url"]=>
    string(53) "https://player.vimeo.com/video/XXXXXXXXX?h=2377ec64ba"
    ["duration"]=>
    int(1)
    ["width"]=>
    int(1080)
    ["height"]=>
    int(1920)
    ["pictures"]=>
    array(1) {
      ["base_link"]=>
      string(106) "https://i.vimeocdn.com/video/1748425125-3250ce8d039eebf63c011233a4babbc9bbc882fd9b85d7a4d832224802fc8167-d"
    }
    ["is_playable"]=>
    bool(true)
  }
}

Querying the posts that contain Vimeo Selection/Upload field data

To query WordPress posts that contain ACF Selection/Upload data using the WP_Query loop on the front-end you will need to use something like this:

$key   = 'vimeo_video'; // the ACF field key.
$query = new WP_Query([
    'post_type'      => 'post',
    'post_status'    => 'publish',
    'posts_per_page' => 6,
    'meta_query'     => array(
        array(
            'key'     => sprintf('_%s_data', $key),
            'compare' => 'EXISTS'
        ),
    )
]);

while ($query->have_posts()) {
    $query->the_post();
    $data = get_field('vimeo_video'); // vimeo_video is the ACF field key
    $additional = get_post_meta(get_the_ID(), '_vimeo_video_data', true); // Cached data.
    echo '<pre>';
    var_dump($data);
    var_dump($additional);
    echo '</pre>';
}