首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress搜索不显示页面的确切结果

Wordpress搜索不显示页面的确切结果
EN

Stack Overflow用户
提问于 2016-06-22 10:31:00
回答 1查看 77关注 0票数 1

我有一个带有以下搜索功能的wordpress网站,它在一些页面上工作得很好,但当我在搜索上使用完全相同的标题时,它不会显示一些页面。可能的原因是什么?请任何人能帮我解决这个问题。提前致谢

代码语言:javascript
复制
                    <?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">&laquo;</span> Older posts', 'evotis' )) ?></div>
                    <div class="nav-next"><?php previous_posts_link(__( 'Newer posts <span class="meta-nav">&raquo;</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代码如下所示

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

发布于 2016-06-22 11:16:45

尝试将此代码添加到您的function.php

代码语言:javascript
复制
function filter_search($query) {
    if ($query->is_search) {
    $query->set('post_type', array('post', 'page'));
    };
    return $query;
};
add_filter('pre_get_posts', 'filter_search');
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37957562

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档