I’ve a little issue, and I couldn’t find anything about it… I’m in deadlock.
So I’ve wp page that contains normal loop, if I call this file directly in browser all works fine, and I can even use query-vars such as: http://domain.com/blog/wp-content/themes/wovies-bones/getmovies.php?actor=x And it works fine, I get single post that has custom taxonomy actor = x.
But when I try to load same using ajax, it behaves differently and ignoring my get request returns all posts…
Any ideas what is happening?
ajax-jquery part:
$.ajax({
url: templatePath + "getmovies.php",
type: "GET",
data: filters_get,
cache: false,
success: function (data){
console.dir(data);
}
});
And php part:
/* Define these, So that WP functions work inside this file */
define('WP_USE_THEMES', false);
require('../../../wp-blog-header.php');
?>
<div id="container">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="movie">
<a href="<?php the_permalink() ?>">
<?php
if (has_post_thumbnail()) {the_post_thumbnail('homepage-preview');}
else {echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/default-poster.jpg" />';}
?>
<p class="comments"><?php comments_number('0 review','1 review','% reviews'); ?></p>
<div class="description">
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
</div>
</a>
</div>
<?php endwhile; else: ?>
<!-- No movies found -->
<?php endif; ?>
</div><!-- End #container -->
filters_get looks like this: ?actor=x&
This way, you just load WordPress and run your own PHP file. Basicaly, I think you should redefine your WP_Query like this :
And if you’re using AJAX to get your posts, you’d better use a hooked function as it is described in WordPress Codex :
Then you will have to use this kind of url in your AJAX call : http://www.domain.tld/wp-admin/admin-ajax.php?action=get_my_cpt&my_tax=keyword