So i have been looking for a couple of days now and cant find a solution to this anywhere. It is a fairly bespoke request from a client... I am using a jQuery google maps plugin to add markers for each post (area) that the admin creates using a custom meta box with lat and long coordinates.
Each of these markers has a tooltip associated with it. In the tool tip i have got some text, the title of each post used to create the marker itself and a permalink to the post (area).
But i would like to display a count of all children posts (deals) of each of the posts (areas).
I have this working on the (area) posts themselves but cannot get them to display in my map tooltips.
This is the code i have so far i dont think i am far away from a solution but my php skills are still at a novice level so any help would be much appreciated.
<script type="text/javascript">
$(document).ready(function(){
var myMarkers = {"markers": [
<?php $items3 = new wp_Query( array(
'post_type' => 'area',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'desc',
) );
$post_id = $post->ID; //or somehow get the current post ID.
$parent_id = get_post_ancestors($post_id);
$parent = get_post_type( $parent_id );
$args = array(
'post_type' => 'deal',
'post_status' => 'published',
'post_parent' => $parent,
'numberposts' => -1
);
$this_page_id=$wp_query->post->ID;
$num = count( get_posts( $args ) );
while ( $items3->have_posts() ) : $items3->the_post(); ?>
{"latitude": "<?php echo get_post_meta($post->ID, '_arealat', true); ?>", "longitude": "<?php echo get_post_meta($post->ID, '_arealong', true); ?>", "icon": "/wp-content/themes/localdoubleglazingdeals/assets/img/design/logo-icon.png", "baloon_text": 'We have <span><?php echo $num ?></span> deals in <strong><?php the_title(); ?></strong><br/><a href="<?php the_permalink(); ?>">View deals</a>'},
<?php endwhile; ?>
]
};
$("#map").mapmarker({
zoom : 7,
center : 'Liverpool',
markers : myMarkers
});
});
it is the...
<?php echo $num ?>
part i am stuck on.