Skip Navigation

[Resolved] Map marker not showing after post creation with Cred form

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a map View that displays markers from posts created in Forms. However, the markers are not immediately added to the map. Only after I edit the posts in the backend do the markers appear in the map.

Solution: In this case it looks like a referrer restriction was implemented on this API key, causing some geocoding issues. Remove restrictions from the 2nd API key, since this key is never exposed in HTML.

Relevant Documentation:
https://toolset.com/documentation/user-guides/maps/display-on-google-maps/creating-a-google-maps-api-key/

This support ticket is created 4 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by David 4 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1494219

I have created a custom post type and one of the fields is a map location.

I have also created a Cred form to create posts from the front end. Once the form is submitted, it is set to be Published. I have a aslo used Cred API to assign a particualar taxonomy term.

Once the form submission is made, the user is redirected to a page showing a map with all post markers. The new post marker should appear on the map but it does not.

The map marker does not appear on the map in my content template for the post either.

But when I look at my post in WP Dashboard, I see that the map and marker have been stored correctly.

I can make my new post marker appear on the maps (in content template and combined view) only by Updating the post from the WP Dashboard.

Post creation form: hidden link

My page with View of all map location is: hidden link

I think this was working for me before I added the function to assign the taxonomy term, so that might have something do to with it.

This is the code I am using to auto-assign the terms:

// automatically assign a slug to all posts created by CRED
add_action('cred_save_data', 'set_term_for_cred_post',10,2);
function set_term_for_cred_post($post_id, $form_data) {
  // array of cred form IDs and corresponding term slugs
  $array = [
    '1527' => 'blood-veined-moth',
    '1533' => 'brown-hare'
  ];
  $taxonomy = 'species';
  $tag = array( $array[$form_data['id']] );
  wp_set_object_terms( $post_id, $tag, $taxonomy, true );
}
#1494245
Screen Shot 2020-02-05 at 9.22.54 AM.png

Hi, I don't think the Forms API code you shared here has anything to do with it. I can see a problem with your Maps API key, as shown in the screenshot here. It looks like the referrer restriction is causing some problems with geocoding addresses. Even though the address is saved correctly, the location isn't geocoded so it's not appearing on the map. You can try setting up a second API key if you'd like, for added security. https://toolset.com/documentation/user-guides/maps/display-on-google-maps/creating-a-google-maps-api-key/

#1494255

My issue is resolved now.
It was a caching issue.

#1494357

OK, it may not have been a caching issue.

OK, so I created a new unrestricted API key, and now it seems to work OK.

But if the key is unrestricted, how can I prevent it from being used be someone else?

#1494573

The unrestricted key should be used in the second API key field, since this key is only used for server-side requests and is never exposed on the front-end of the site. Does that make sense?

#1496237

My issue is resolved now. Thank you!