I'm trying to load a php file into a div#main when a link is clicked. The html content loads but the actual php code included in the file does not. Here's what I've got:
Link to trigger everything:
<a id="nav" href="http://domain.com/inc/file.php">
jQuery:
jQuery(document).ready(function($) {
$("#nav").on('click', function (e) {
e.preventDefault();
$("#main").empty();
$.ajax({
url: $("#nav").attr('href')
}).done(function(data) {
$('#main').html(data); // display data
});
});
});
Code from file.php (mostly WordPress functions):
<div id="hostels" class="section cf">
<?php get_a_post(31); ?>
<article id="swiss" <?php post_class('swiss bg col span-1-3'); ?> role="article">
<h3>
<a href="<?php the_permalink(); ?>">
<span class="logo-pl-small"><?php include(TEMPLATEPATH . '/library/svg/logo.svg'); ?></span>
<span class="">Swiss Cottage – London UK</span>
</a>
</h3>
<?php if ( has_post_thumbnail()) { the_post_thumbnail(); } ?>
<div class="entry-content">
<?php the_excerpt(); ?>
<?php edit_post_link( __( 'Edit', 'bonestheme' ) ); ?>
<?php if ( get_post_meta($post->ID, 'vidlink', true) ) {
echo apply_filters('the_content', get_post_meta($post->ID, 'vidlink', true));
} ?>
</div>
</article>
</div>
OUTPUT:
<div id="main">
<div id="hostels" class="section cf">
</div>
</div>
The file begins to load but as soon as <?php get_a_post(31); ?> is reached, the file does not continue to load.
I could be wrong, but I thought that by using $.ajax the php code would execute on the server and code it outputs would load into my #main div.
<?php ini_set('display_errors', 1); ?>in the beginning offile.phphttp://domain.com/inc/file.phpin your browser and see what happends / the output is.Fatal error: Call to undefined function get_a_post(). I'm going to try some generic php to see if that works, then may need to use a different method.