Rya*_*yan 7 wordpress search themes
我正在使用我自己的自定义WordPress主题,使用空白的默认模板启动.我没有编辑search.php文件.
我的很多WordPress帖子都是Pages.不幸的是,网站搜索只检索帖子,而不是页面.
知道如何让主题搜索帖子和页面吗?
这是search.php的大部分内容:
<?php if (have_posts()) : ?>
<h3>Search Results</h3>
<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
<div class="entry">
<?php the_excerpt(); ?>
</div>
</div>
<?php endwhile; ?>
<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
<?php else : ?>
<h3>No posts found.</h3>
<?php endif; ?>
Run Code Online (Sandbox Code Playgroud)
小智 34
将此代码添加到functions.php文件中.
function wpshock_search_filter( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', array('post','page') );
}
return $query;
}
add_filter('pre_get_posts','wpshock_search_filter');
Run Code Online (Sandbox Code Playgroud)
http://wpth.net/limit-wordpress-search-results-to-specific-post-types