• Resolved pred88

    (@pred88)


    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&#8221;, ”, 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 ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • It doesn’t work because you script is executing ‘outside’ the WP framework and so query_posts is not defined. If you include wp-config.php into the top of your file it should work. I think it also works if you include wp-setting.php.

    Thread Starter pred88

    (@pred88)

    Yea that makes sense. I tried including wp-config or wp-header but I get file access is disabled error. Any idea how I can properly include it ?

    Thread Starter pred88

    (@pred88)

    Nevermind, I needed to use absolute link. Works fine now thanks 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Jquery Ajax in wordpress’ is closed to new replies.