I've got a exterior php file that queries the Wordpress database for posts. I personally use the Wordpress_Query class to personalize my queries. It runs fine if I am inside the template files, however it will not after i give a new php file.

I must range from the functions that Wordpress uses to my file.

Ajax-nao.php

$categoryid = $_GET['cat'];
 $postnum = $_GET['ponum'];
 $pagenum = $_GET['panum'];

$args = array (
        'cat' => $categoryid,
        'posts_per_page' => $postnum,
        'paged' => $pagenum
);
$q = new WP_Query($args);
while( $q->have_posts()) : $q->the_post();
    $post_excerpt = get_the_excerpt();
    $wrapper = '<h2 class="column-titles">' . get_the_title() . '</h2>' . '<p>' . $post_excerpt . '</p>';
    echo $wrapper;
exit();
endwhile;
echo "No results found!";

After I run it I recieve this error

Fatal error: Class 'WP_Query' not present in I:xampphtdocsdmpwp-contentthemesdmp-v3Ajax-nao.php online 11

Also, it is possible to method to for $.get() to load the my php during my theme folder and never within the root directory?

Thanks.

From some investigation, try adding this to the peak of the PHP file and alter PATHHERE towards the actual path:

// Include WordPress
define('WP_USE_THEMES', false);
require_once('PATHHERE/wp-blog-header.php'); 

For reference:

I want to run wp_query on a separate php file for an ajax call

wordpress loop with jquery .load()