我有一个带有以下搜索功能的wordpress网站,它适用于某些页面,但是当我在搜索时使用完全相同的标题时,它不显示某些页面。可能是什么原因呢?请任何人帮我解决这个问题。 非常感谢提前
<?php dynamic_sidebar('header-link'); ?>
<div class="clear" style="clear:both; width:100%; height:auto;"></div>
<div class="content">
<?php dynamic_sidebar('mobile-widget'); ?>
<div class="mainbar">
<?php the_post(); ?>
<div class="article">
<?php if (is_active_sidebar('sidebar-1')) : ?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar('sidebar-1'); ?>
</div><!-- #secondary -->
<?php endif; ?>
<?php if ( have_posts() ) : ?>
<h1 class="page-title"> <?php echo get_theme_mod('search_result_text', 'Search Results Found For'); ?> <span><?php the_search_query(); ?></span></h1>
<?php while ( have_posts() ) : the_post() ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( __('Permalink to %s', 'evotis'), the_title_attribute('echo=0') ); ?>" rel="bookmark"><?php echo get_post_meta($post->ID, '_yoast_wpseo_title', true); ?></a></h2>
<div class="entry-summary">
<?php echo get_post_meta($post->ID, '_yoast_wpseo_metadesc', true); ?>
<div class="h-readmore"> <a href="<?php the_permalink(); ?>"><?php echo get_theme_mod('readmore', 'Lees artikel'); ?></a></div>
</div><!-- .entry-summary -->
</div><!-- #post-<?php the_ID(); ?> -->
<?php endwhile; ?>
<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 ) { ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php next_posts_link(__( '<span class="meta-nav">«</span> Older posts', 'evotis' )) ?></div>
<div class="nav-next"><?php previous_posts_link(__( 'Newer posts <span class="meta-nav">»</span>', 'evotis' )) ?></div>
</div><!-- #nav-below -->
<?php } ?>
<?php else : ?>
<div id="post-0" class="post no-results not-found">
<h2 class="entry-title"><?php _e( 'Nothing Found', 'evotis' ) ?></h2>
<div class="entry-content">
<p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'evotis' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</div>
<?php endif; ?>
<?php if (is_active_sidebar('sidebar-2')) : ?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar('sidebar-2'); ?>
</div><!-- #secondary -->
<?php endif; ?>
</div>
</div>
<?php get_sidebar(); ?>
<div class="clr"></div>
</div>
</div>
<?php get_footer(); ?>
searchform.php代码如下所示
<div class="searchform search" rol="search">
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
<input type="search" value="<?php the_search_query(); ?>" name="s" id="s" placeholder="<?php echo get_theme_mod('search_placeholder', 'Search: Enter Your keywords'); ?> "/>
<input type="submit" class="sbutton" alt="Search" value="search"/>
</form>
</div>
答案 0 :(得分:0)
尝试在function.php上添加此代码
function filter_search($query) {
if ($query->is_search) {
$query->set('post_type', array('post', 'page'));
};
return $query;
};
add_filter('pre_get_posts', 'filter_search');