Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Maps JSON & Wordpress
    text
    copied!<p>I have a google map in my wordpress site, this map collects markers that are created from posts. To explain a little better, a user add's an item, that item is then placed on a map based on location and then a total inventory needs to be totaled. Each location should only generate one marker and the total inventory of that marker's product. I have a few select dropdown's that let the use filter through the markers, and on change, updates an ajaxed php file, which builds a json file of the results, which the maps javascript then loops through and displays.</p> <p>I have everything displaying, but, I can't get the markers to group by location and the total inventory to display. I think the ultimate solution would be to have the php script that generates the json file create one marker per location with the totals, eliminating the need for filtering with javascript. Here is my PHP that creates the JSON file.</p> <pre><code>&lt;?php //Header include "../../../../wp-blog-header.php"; global $wpdb; //$wpdb-&gt;show_errors(); $eq_type = $_GET['eq_type']; $sql = " SELECT wp_posts.ID, wp_postmeta.meta_value, wp_postmeta.meta_key FROM wp_posts LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id WHERE wp_posts.post_type = 'equipment' AND wp_posts.post_status = 'publish' AND wp_postmeta.meta_key NOT LIKE '%_yoast_wpseo%' AND wp_postmeta.meta_key NOT LIKE '%_edit%' "; $posts = $wpdb-&gt;get_results($sql); $arr = array(); foreach ($posts as $post): $arr["item-".$post-&gt;ID][$post-&gt;meta_key] = $post-&gt;meta_value; //print $post-&gt;ID.' - '.$post-&gt;meta_key." - ".$post-&gt;meta_value."&lt;br /&gt;"; endforeach; $fp = fopen('../json/json-equipment.json', 'w'); fwrite($fp, json_encode($arr)); fclose($fp); ?&gt; </code></pre> <p>And it generates JSON output like this...</p> <pre><code> { "item-111": {"eq_type":"Dump Truck","eq_region":"Alberta","eq_total_inventory":"123"}, "item-112": {"eq_type":"Dump Truck","eq_region":"British Columbia","eq_total_inventory":"234"}, "item-113": {"eq_type":"Dump Truck","eq_region":"British Columbia","eq_total_inventory":"23"}, "item-114": {"eq_type":"Digger","eq_region":"Manitoba","eq_total_inventory":"23"} } </code></pre> <p>So hopefully i've been clear enough, need to generate only 1 marker per location, with the total inventory of each location add'ed up that filters by Type and/or Region... but the grouping and totalling is what is really stumping me. Ask for any information!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload