在我的博客上搜索我的不起作用

时间:2015-07-25 作者:user55212

我已经尝试了几个小时,如果不是一天的话,来尝试获取我的自定义搜索。php和searchform。php的工作,但仍然没有成功。我已经阅读了很多关于这两个模板的内容,但仍然没有成功。

这是我的搜索。php:

<div class="post-wrap">
    <?php if ( have_posts() ) : while (have_posts()) : the_post(); ?>
        <?php the_title( sprintf( \'<h2 class="entry-title"><a href="%s" rel="bookmark">\', esc_url( get_permalink() ) ), \'</a></h2>\' ); ?>
        <?php the_excerpt(); ?>
    <?php endwhile; else: ?>
        <p>Woops There is no post yet</p>
    <?php endif; ?> 
</div><!-- /.social-media-posts -->
这是我的搜索表。php:

<form action="<?php echo home_url( \'/\' ); ?>" id="searchform" class="search-form" method="get" role="search">
    <input type="text" id="s" placeholder="Search" class="search-field">
    <input type="submit" value="&#xf002;" id="searchsubmit" class="search-submit">
    <a class="search-close" href="#"><i class="fa fa-times-circle"></i></a>
</form>
最后,这就是我用来称之为searchform的东西。我的导航模板中的php:

<?php get_searchform(); ?>
还是没什么用,我有点泄气了。如果有任何帮助,我将不胜感激。谢谢

2 个回复
SO网友:Jonathan Foster

看起来您实际上并没有在表单中获取搜索查询。您需要包括value="<?php the_search_query(); ?>" 在您的输入字段中。

Here is a link to the docs for the search form.

我想你要找的是“主题表单”标题下的内容。

SO网友:Makiomar

你错过了name 属性您只需要像这样将其添加到输入字段

<input type="text" id="s" name="s" placeholder="Search" class="search-field">
任何输入字段都是用来获取数据进行查询的name 属性是必需的。

结束

相关推荐

Search tags in CPTs

我似乎不知道如何在wordpress搜索中包含标签。例如,如果我搜索“apple”,我希望在标题或内容中返回带有“apple”的帖子(默认wordpress功能)as well as 包含标签“apple”的帖子;当我添加\'tag\' => $keyword 行到WP\\u查询中,然后每次搜索都没有结果。$keyword = get_search_query(); $args = array( \'post_type\' => array(\'case_studie