Home Forums Front-end Issues Using Blade with custom post types and ACF Group Fields


Using Blade with custom post types and ACF Group Fields

  • I have an ecoprovince field group with two fields. The one I want to target in my blade.php file is the Eco Province Locations. And in the Eco Province Locations specifically the field polygon_area_coordinates_for_ecozone. You Should be able to see them in my provided screenshots.The coordinates are dumped into a custom post type called ecoprovince.

    I have the following blade php code

    // Set up the arguments for WP_Query
    $args = [
    'post_type' => 'ecoprovince', // Replace with your custom post type
    'posts_per_page' => -1, // Fetch all posts
    'fields' => 'ids', // Only get post IDs to improve performance

    // Perform the query
    $eco_zone_posts = new WP_Query($args);

    // Initialize an array to store our eco zones data
    $eco_zones_data = [];

    // Loop through the posts
    foreach ($eco_zone_posts->posts as $post_id) {
    // Retrieve the entire group field 'ecoprovince_locations' first
    $ecoprovince_locations = the_field('ecoprovince_locations', $post_id);

    // Now you can access the subfield 'polygon_area_coordinates_for_ecozone'
    // Ensure you access the subfield as a key of the group field array
    $coordinates = get_sub_field('polygon_area_coordinates_for_ecozone') ?? '';

    // Check if coordinates are not empty and add them to the array
    if (!empty($coordinates)) {
    $eco_zones_data[] = [
    'coordinates' => $coordinates,
    wp_reset_postdata(); // Important to reset post data after a custom query

    {{-- Debug output --}}
    <div class="debug-output">

    Right now it outputs an empty array for the coordinates but there are coordinates in the post, there are two posts with coordinates published.

    trying to figure out how to output the coordinates into an array after looping through them.

    thanks ahead of time.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.