我正在开发一个使用WP CMS的网站,我想在这里实现帖子标题作为下拉列表,以及当用户选择下拉标题时,在重新加载中显示以下内容。我在这里。如果我想按id检索内容,我该怎么办?
function select_options(){ ?>
<form action="" method="POST">
<select name="count" id="selectId" >
<?php
$posts = new WP_Query(array(\'posts_per_page\' => 3, \'post_type\' => \'post\'));
while($posts->have_posts()) : $posts->the_post(); ?>
<option id="selection" value="<?php echo get_the_ID(); ?>"><?php echo get_the_title(); ?></option>
<?php endwhile;
die()
?>
</select>
</form>
<?php
}
add_action(\'wp_ajax_select_option\', \'select_options\');
add_action(\'wp_ajax_nopriv_select_option\', \'select_options\');
Javascript:
jQuery(document).ready(function(){
jQuery.ajax({
//var count = $(\'#selection\').val();
type: \'POST\',
url: \'wp-admin/admin-ajax.php\',
data:{
action: \'select_option\'
//count: count;
},
dataType: \'html\',
success: function(data){
jQuery(\'.content\').html(data)
},
error: function(){
alert(fail)
}
})
});