is it possible to dynamically add markers to a map based on post content? I’m using the WP meta box on posts to add the location information to the map, and I also have a search & filter function on my site that displays posts based on whatever the user wants to filter them as, so I’m trying to get both (search form and maps) to work together. I’m using the shortcode to display the map, and I’m using a shortcode to display the search and filter form. I’m trying to figure out the loop to be able to tell the maps to look at the post results first before adding any markers and to only display the markers that match the posts from the search form.

I’m using this hook in my function.php file, and I would like the markers to only show if the search form returned certain locations:


function add_markers($markers,$map_id)
return $markers;

What is the code that matches the marker id to the post title when displaying markers on a map?

Please check this hook here https://gist.github.com/wpflippercode/57c72a7e5adc2c7f0ee113756fcf360a

I hope it helps you to achieve as you need.

Can you please explain what that code is supposed to do? it doesn't seem to be working right now. Can you please explain? Does the $places argument work to return $markers? I tried this code and now the map doesn't show any markers, so I'm thinking I have to use this with something else perhaps?
This code displays Markers on Google Maps According to Post ID in the WordPress. You need to insert your post id like this ($post->ID == 1 ) Your id will be different. You only need to replace the id and that id posts will be shown on a map.
I want my map to show the markers based on the page content not based on the post ID. For example, I have 500 locations, and each location has tags, categories, filters, custom fields, etc., and I have a search form and filter function that filters the posts/locations based on the filter or search choice, so, if the user clicks on one of the post tags, they land on a page that displays different post titles with excerpts, so, I want those 'filtered' locations (which are set up as different posts) to show as markers on the map that I have displaying on that page.

I am able to show ALL markers because I used the wpgmp meta box to add the location to the map, but what I need is for the markers to update dynamically based on whatever different location tags the user chose. Does that make sense?

I'm thinking it might be something like this (assuming that the $marker_title is the correct way of matching the $places to the search query results from the filter form):

add_filter('wpgmp_markers','wpgmp_markers',1,3 );
function wpgmp_markers($places,$map) {
global $post;
if($query->the_title == $marker_title) {
$places = array_slice($places, 1,10);
else {
$places = array_slice($places, 20,10);
return $places;

IF $marker_title is NOT the argument, can you tell me what the appropriate one is?

Thank you,

Please login or Register to Submit Answer