Hi All,
This seems like it should be easy, but I've been pulling my (thinning) hair out getting it to work. What it boils down to is, how do I get the content of a post from the wordpress database and replace the contents of an HTML <div> with that content?
At page load time, I have php that generates the post ID for the corresponding image, i.e.:
onmousedown="javascript:getDescription('<?php the_ID(); ?>');"
That onmousedown() calls a javascript that passes the value of the post I want to query to a php file, i.e.:
<script type="text/javascript">
function getDescription(for_id) {
$.ajax({
type: 'GET',
url: "<?php bloginfo('template_url'); ?>/assets/includes/get-description.php?id=" + for_id,
success: function(data, textStatus, jqXHR){
$('#textdescription').html(data);
}
});
}
</script>
The php file get-description.php then should do the query and return the post contents, which the javascript then uses to update the <div> contents:
<p><?php
$contentVar = $_GET['id'];
$post = get_post($contentVar);
$content = $post->post_content;
echo $title;
?></p>
So this is all tested and working, except for the php file that is supposed to do the database query--- I can't get it to return anything when I query. I can return other content including my incoming post id, so I know all the pipes are connected and working.
Any help appreciated, thanks in advance!