What to include in php page to use wordpress’s functions?

I have a wordpress website and I want to create a page that also has javascript and upon a certain user action the javascript calls the server with an AJAX request.
This is a GET request to a php script I created. Since I extended wordpress with my plugin I put this php in my plugin’s folder.

The problem is that from this php script I want to access everything that wordpress offers, e.g. the database access, but I do not know how.

Read More

What do I have to include in this php file in order to access the functions offered by wordpress? I wanted to use database access so I included the wp-db.php file and declared the global wpdb variable, but it did not help.

Can anyone tell me how to accomplish this?

Thanks in advance!

Related posts

Leave a Reply

2 comments

  1. As recommended in he WordPress Codex itself.

    <?php 
    /* Short and sweet */
    define('WP_USE_THEMES', false);
    require('./wp-blog-header.php');
    ?>
    

    By using the blog header no database queries are executed by default, you have to supply the get_posts that will fetch what-ever articles you need based on your application’s parameters:

    <?php $posts = get_posts('numberposts=10&order=ASC&orderby=post_title'); ?>
    <?php foreach ($posts as $post) : start_wp(); ?>
        <?php the_date(); echo "<br />"; ?>
        <?php the_title(); ?>    
        <?php the_excerpt(); ?> 
    <?php endforeach; ?>