Dynamic Content in Map no longer works after upgrading to Pro 5 (even with the 5.0.2 update)

This morning I updated our website from Pro 4.3.3 to Pro 5.0.1 (and just before posting this, to 5.0.2).

After the update, a bunch of things were messed up. I was able to fix most of them, except this.

Inside of a Map element, under “Setup”, for “Latitude” and “Longitude” I have two custom dynamic content strings, generated by a function I snagged from a post from @alexander on Dynamic Maps. Below is the code I’m using, with two very small adjustments: “location” → “map” and “acfpro” → “acf” (neither of these changes are causing the issue):

// Get dynamic location data from event

/*
{{dc:acf:field name="map" key="lat"}}
{{dc:acf:field name="map" key="lng"}}
*/

// add a filter to supply data for {{dc:acfpro:*}} tags
add_filter( 'cs_dynamic_content_acf', function($result, $field, $args = array()) {

  // supply results to {{dc:acf:field name="..."}} tags
  if ( $field === 'field' && isset( $args['name'] ) ) {
    
    // get the data for the named field
    $data = get_field( $args['name'] );

    if ( is_scalar( $data ) ) { 
        $result = $data;   // If it is a string or numeric, pass it through directly
    } else if ( is_array( $data ) && isset( $args['key'] ) && isset( $data[$args['key']] )) {
        // If it is an array and a key argument is present, pass through the requested key
        $result = $data[$args['key']];
    }

  }

  return $result;

}, 10, 3 );

I’ve confirmed this works by including {{dc:acf:field name="map" key="lat"}} and {{dc:acf:field name="map" key="lng"}} in a text snippet on the same page, and it pulls the correct value. But after upgrading Pro to v5, there seems to be something wrong in how the map’s latitude and longitude are now pulling (or not pulling)
dynamic content.

I will include login creds and specific URLs to reference in a private note.

Hi @SJF_me,

I tried logging in but I’m getting a VERIFICATION REQUIRED error. Before we try that, I think a good place to start would be removing that custom code altogether. In Pro 4.2 we added a much more robust ACF integration that will let you access those fields.

It would be better to just re-add those fields using the new ACF integration instead of the custom code.

Sorry about that. I’ve disabled our firewall, could you try again?

I cannot seem to find anything regarding the ACF integration you’re referring to. Would you be able to lead me in the right direction here?

@alexander - When adding {{dc:acf:post_field field="map"}} I get an array, with the address1, address2, city, state, country, latitude, longitude but I’m unable to isolate the last two items as separate values like I can with the custom code.

Also, while I appreciate the suggestion to use the “new ACF integration instead of the custom code”… I can’t seem to get any type of dynamic content to work in the latitude & longitude fields. This wasn’t the case prior to updating to Pro 5.

Thanks! I’ve checked again was able to confirm this is an issue in Pro 5. We’ll get it corrected for the next update. It doesn’t parse those values properly in the map element.

I did go ahead and update the map to use the new way of accessing ACF post fields. Targeting the map field type takes a bit of extra setup since we need to add a Looper Provider to load the entire map field, then we can access its properties. I’ve adjusted your Map Column to do this correctly.

And here’s an article explaining how it works: https://theme.co/docs/acf-pro-and-loopers#singular-fields

When the next point release is pushed it should start working again.

@alexander - I’ve updated to 5.0.3 and it works when using your looper method! I’m wondering, though, why won’t the custom code work anymore? I realize I don’t need it, with this new method, but I’m just curious as to why exactly it isn’t working. If it’s returning a number, and that field takes a number, why wouldn’t it work the same?

@SJF_me,

The bug fixed in Cornerstone was the Google Map fields stopping processing dynamic content altogether, so that’s why it wasn’t working. I’m actually not sure that the custom code doesn’t still work. I just updated that column as an example since it would be better to just use the official ACF integration method instead of relying on a customization.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.