您可以使用WP_query()
要缩小搜索结果的范围,请执行以下操作:
<?php $args = array(
\'s\' => $_GET[\'s\'],
\'post_type\' => array( \'post\', \'page\' ),
\'post_status\' => \'publish\',
\'category_name\' => \'music\',
\'posts_per_page\' => -1
);
$custom_search = new WP_Query( $args );
if ( $custom_search->have_posts() ) {
while ( $custom_search->have_posts() ) : $custom_search->the_post(); ?>
<div class="entry-content">
<h2 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
</div>
<?php endwhile;
} else { ?>
<h2>Your search didn\'t return any results.</h2>
<?php } ?>