所以我选择了3个选项:男士,女士,男女皆宜。每当用户选择新选项时,都应重新加载帖子。我现在把它作为ajax功能:
$(document).ready(function () {
$('#select-gender').change(function(){
$.ajax({
url: ajaxurl + "/woocommerce/archive-content.php",
type: "post",
data: {option: $(this).find("option:selected").val()},
success: function(data){
//adds the echoed response to our container
$("#topdog").html(data);
}
});
});
});
这是archive-content.php文件:
<?php
function details($opt) {
echo 'option: ' . $opt;
}
details($_POST['option']);
$selected = $_POST['option'];
// The Query
$the_query = new WP_Query( $args );
$args=array(
'gender' => $selected,
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo 'List of manly product';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
我现在意识到只更改$ selected变量不会重新加载我的帖子。我应该在“数据”中加载我的帖子吗? ajax函数的一部分?我该怎么做?
谢谢!