我正在尝试使用ajax将搜索结果放入div中。问题是我在说undefined function have_posts()
访问搜索模板时。它还对get_header()
在搜索结果中。php,但我把它取出来了。下面是我如何设置它的。
<div id="my_search">
<form role="search" method="get" id="searchform" action="http://myurl.com/" >
<input type="text" value="" name="s" id="s" />
<input type="submit" id="searchsubmit" value="Search" />
</form>
</div>
<div id="results"></div>
<script type="text/javascript">
$(document).ready(function(){
$("#searchsubmit").click(function(e){
e.preventDefault();
var search_val=$("#s").val();
$.post(\'http://mysite.com/wp-content/themes/beta/search-results.php\',{search_string:search_val},function(data){
if(data.length>0){
$("#results").html(data);
}
});
});
});
</script>
这是search-results.php
样板我想知道我是否没有将搜索结果传递给模板。<ul>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a title="Permalink to this post" href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
<?php if (!have_posts()) { echo(\'<li>No results to show.</li>\'); } ?>
</ul>