我想通过点击ajax链接并将新结果加载到我的div来更改query_posts
我在single.php中使用此代码
使用顶部的<_GET函数
if( !empty($_GET['key']) )
$meta_key=$_GET['key'];
else $meta_key= ''; // default
下拉列表
<form action="" method="get">
<select name="key" id="fromchange" class="style-select"onchange="if(this.value != 0) { this.form.submit(); }">
<option value="">""</option>
<option value="artist_artist" <?php if ($key == "artist_artist") { echo 'style="color:gray" selected'; } ?>> ACTOR</option>
<option value="artist_director" <?php if ($key == "artist_director") { echo 'style="color:gray" selected'; } ?>> DIRECTOR</option>
</select>
</form>
phpcode和div的新结果是:
<div id="result">
<?php // ACTORS
$title1='>'. get_the_title() .'</a> ('.get_field('date').')';
$title2='>'. get_the_title() . ' ('.get_field('date').')';
$args_actor=array(
'post_type'=> 'post',
'cat' => '5',
'posts_per_page'=> -1,
'orderby' => 'title',
'order' => 'ASC',
);
$crew_query = null;
$crew_query = new WP_Query(array($args_actor,
'meta_query'=> array('relation' => 'OR',
array('key'=>$meta_key,'value'=> $title1,'compare'=>'LIKE'),
array('key'=>$meta_key,'value'=> $title2,'compare' => 'LIKE'))
));
if( $crew_query->have_posts() ) {
echo'<ul class="mpanel">';
while ($crew_query->have_posts()) : $crew_query->the_post();
include (TEMPLATEPATH . '/single-movie/content-list-movie-crew.php');
endwhile;echo '</ul>';}
else{
echo'<ul class="mpanel">';
include (TEMPLATEPATH . '/single-movie/movie-crew-else.php');
echo '</ul>';
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
</div>
如何运行此代码并通过单击div中的ajax来更改查询?