Support » Plugins » Hacks » Problem with including PHP file

  • Moderator justingreerbbi


    Forum Moderator

    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!!!

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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?

    I think you would include wp-load.php to do that, but really you should be hooking into the WP AJAX responder. See

    Moderator justingreerbbi


    Forum Moderator

    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

    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 and not

    Any help?


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

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Problem with including PHP file’ is closed to new replies.