Problem with including PHP file (5 posts)

  1. Justin Greer
    Volunteer Moderator
    Posted 3 years ago #

    Ok So this is driving me crazy..

    Basically I am trying to pull from the database and out the format in JSON using php. I had the file (mapdata.php) in a folder in the root of the installation. I included the wp-blog-header.php and if I went directly to the file in the browser it would work and output what I wanted.

    So I then have a custom page template that I am have integrated Google maps.

    I need to include the php file(mapdata.php) I created earlier into the custom page template but it will not let me. I tried moving mapdata.php to the root dir of the theme and then I could not use it because it would ot include get_bloginfo() or get_header() so that I could connect to the database. I know there is a way but I can't seem to find out how to do it.

    Does anyone have any idea what I need to do to get it to work like I want it to. This is a custom script for a client so I can not use a plugin.

    Thanks in advance!!!

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    Are you sure that this isn't just one or more file path issues? when you moved the file into the theme, did you remember to adjust the paths within mapdata.php?

  3. Paul Clark
    Posted 3 years ago #

    I think you would include wp-load.php to do that, but really you should be hooking into the WP AJAX responder. See http://codex.wordpress.org/AJAX_in_Plugins

  4. Justin Greer
    Volunteer Moderator
    Posted 3 years ago #

    Thanks for the replies,

    I have chosen a different route. I am trying to call the mapdata.php file using Google map v3 JS.

    Here is part of the code:

    function initialize() {
        var myLatlng = new google.maps.LatLng(37.4419, -122.1419);
        var myOptions = {
          zoom: 13,
          center: myLatlng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        downloadUrl("mapdata.php", function(data) {
          var markers = data.documentElement.getElementsByTagName("marker");
          for (var i = 0; i < markers.length; i++) {
            var latlng = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")),
            var marker = new google.maps.Marker({position: latlng, map: map});

    This code is in the template file I created.
    everything is working but the markers for the Google map.

    I think the reason is that the permalink for the page I created is

    As you can see above I am trying to call the mapdata.php file relative to the the acualt page-template.php and not sitename.com/map/mapdata.php

    If you have not noticed I am using permalinks.

    I think the script is looking for mapdata.php file relative to the permalink and not the actual file path.

    I hope this makes since. I am trying to get the script to call the file but it is looking for it at sitename.com/map/mapdata.php and not

    Any help?


  5. Paul Clark
    Posted 3 years ago #

    Just use an absolute path. downloadUrl("/wp-content/themes/template/mapdata.php" ...

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.