Ok. I've been playing around but am still none-the-wiser! So if I post my code, it may help.
I've got header.php with this:
Code:
<script>
$(document).ready(function(){
$.ajaxSetup({cache:false});
$(".locationID").click(function(){
var post_id = $(this).attr("rel");
//alert($(this).attr('rel'));
$("#single-home-container").html("loading...");
$("#single-home-container").html(post_id);
$.post("test.php", {"locationID": post_id}, function (txt) {
alert(txt);
});
return false;
});
});
</script>
I then have footer.php which lists all the dynamic links:
Code:
<ul>
<?php
$args = array(
'post_type' => 'locations',
'order' => 'DESC'
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<li><a href="#" rel="<?php the_ID(); ?>" class="locationID"><?php the_title(); ?></a></li>
<?php
endwhile;
wp_reset_query();
?>
</ul>
In footer.php, I also include a call to a file:
Code:
<?php include(TEMPLATEPATH."/test.php"); ?>
In test.php I want to show the result of the selected link:
Code:
echo 'Footer with location id of ' . $_POST['locationID'];
$the_location_id = $_POST['locationID'];
<?php
$args = array(
'post_type' => 'locations',
'posts_per_page' => 1,
'p' => $the_location_id ,
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<?php the_title(); ?>
<?php
endwhile;
wp_reset_query();
?>
So As you can see, I'm trying to get the id of the clicked link, pass it to a php variable which I can then use in a query. From what's shown above, surely that's correct? But if I echo the variable
Code:
echo $the_location_id;
nothing is shown
Sorry to keep posting but I really would like to get to grips with it and see what I've done wrong.
Thanks again
Bookmarks