Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $new = new WP_Query('post_type=kml');
- while ($new->have_posts()) : $new->the_post();
- if(get_field('marker_datas')):
- while(the_repeater_field('marker_datas')):
- $name = the_sub_field('placemark_name');
- // it seems the variables don't store the values - can't echo them, I get only an empty h2
- //echo '<h2>' , $name , '</h2>';
- $description = the_sub_field('placemark_text');
- $styleUrl = the_sub_field('placemark_style_id');
- $Point = the_sub_field('placemark_coordinates');
- endwhile;
- endif;
- endwhile;
- class Placemark
- {
- public $name;
- public $description;
- public $styleUrl;
- public $Point;
- function __construct(
- $name, $description, $styleUrl, $Point)
- {
- $this->name = $name;
- $this->description = $description;
- $this->styleUrl = $styleUrl;
- $this->Point = $Point;
- }
- }
- //make placemark object
- $placemarks = array(
- new Placemark(
- // these variables not working unless I type the values themselves here, the xml nodes are empty
- 'this is a placemarks name',
- $description,
- $styleUrl,
- $Point
- )
- );
- //create the xml document
- $xmlDoc = new DOMDocument();
- //create the root element
- $root = $xmlDoc->appendChild(
- $xmlDoc->createElement("Document"));
- foreach($placemarks as $marker)
- {
- //create a marker element
- $markerTag = $root->appendChild(
- $xmlDoc->createElement("Placemark"));
- //create the name element
- $markerTag->appendChild(
- $xmlDoc->createElement("Name", $marker->name));
- //create the desc element
- $markerTag->appendChild(
- $xmlDoc->createElement("Description", $marker->description));
- //create the styleURL element
- $markerTag->appendChild(
- $xmlDoc->createElement("styleUrl", $marker->styleUrl));
- //create the coordinate element
- $coordTag = $markerTag->appendChild(
- $xmlDoc->createElement("Point"));
- $coordTag->appendChild(
- $xmlDoc->createElement("coordinates", $marker->Point));
- }
- header("Content-Type: text/plain");
- //make the output pretty
- $xmlDoc->formatOutput = true;
- echo $xmlDoc->saveXML();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement