Jquery Ajax in wordpress
-
Hi,
I am trying to auto refresh a div using jquery (for the animation) and Ajax (for the auto refresh). I am doing this by executing a wordpress query every few seconds. The query has been put in a seperate php file.
However, i’m getting an error that keeps refreshing every 3 seconds with an animation so I asume the ajax and jquery part is working.
Fatal error: Call to undefined function query_posts() in aanbieding.php on line 9
None of the wordpress queries I use in the inlcuded aanbieding.php seem to work. The code I used to auto refresh is:
<script type=”text/javascript”>
function getRandom() {
$(“#aanbieding”).hide(“slow”);
$(“#aanbieding”).load(“http://ijzerhandel-amsterdam.nl/new/wordpress/wp-content/themes/ijzerhandel/aanbieding.php”, ”, callback);
}function callback() {
$(“#aanbieding”).show(“slow”);
setTimeout(“getRandom();”, 3000);
}$(document).ready(getRandom);
</script>
PHP code:
<?php query_posts(array(‘orderby’ => ‘rand’, ‘category_name’ => aanbieding, ‘showposts’ => 1)); if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id=”aanbieding_image”>
<?php echo get_image(‘product_foto’); ?>
</div>
<div id=”aanbieding_prijs”>
<h1 class=”prijs”><?php echo get(‘prijs’); ?></h1>
</div>
<div id=”aanbieding_beschrijving”>
<h1 class=”aanbieding”><?php the_title(); ?> </h1>
<?php echo get(‘aanbieding_beschrijving’); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>url to site: http://ijzerhandel-amsterdam.nl/new/wordpress/
Does anyone know why the queries are not working ?
The topic ‘Jquery Ajax in wordpress’ is closed to new replies.