rhum
rhum

Reputation: 41

acf on wordpress problem with Field Googlemap

I have a wordpress with acfpro. I use it the options page for to create option page header and footer, next I declare custom field map on option page footer and paste code in footer.php. when I do it this, i have some pages where acf map not working and other pages is good! wordpress 5.2, acfpro 5.7.13

 <div class="left">
        <div class="zto-containMap">
            <?php
            $location = get_field('map');
            $long = $location['lng'];
            $lat = $location['lat'];
            if( !empty($location) ):
                ?>
                <div class="acf-map">
                    <div class="marker" data-lat="<?php echo $lat; ?>" data-lng="<?php echo $long; ?>"></div>
                </div>
            <?php else: ?>
                <div class="acf-map">
                    not working
                </div>
            <?php endif; ?>
        </div>
    </div>

I don't have a error message, and acf map is broken on 3 page on my site and the other pages are working nice width acf map

Upvotes: 2

Views: 50

Answers (1)

domdambrogia
domdambrogia

Reputation: 2243

If you want to get the field value for an option, you have to declare the option scope in your second paramter of get_field($field, $scope). If no $scope is passed in the get_field() function it will automatically use the ID value of get_post().

This is what you're after:

$location = get_field('map', 'option');

Here's the docs on getting the value of an Option field in ACF.

While this is a little out of the scope of your question, these docs explain a little further about how the $scope variable can be used in the second parameter.

Upvotes: 1

Related Questions