Wordpress-如何仅搜索页面
我需要一些Wordpress搜索方面的帮助。我想知道的是如何只搜索Wordpress页面。你可能想在Wordpress论坛上查看这个。 您必须在搜索表单中添加一个隐藏表单字段,并添加一个钩子来更新wordpress生成的查询 编辑:这是上面提到的论坛帖子的代码 在搜索表格中:Wordpress-如何仅搜索页面,wordpress,search,Wordpress,Search,我需要一些Wordpress搜索方面的帮助。我想知道的是如何只搜索Wordpress页面。你可能想在Wordpress论坛上查看这个。 您必须在搜索表单中添加一个隐藏表单字段,并添加一个钩子来更新wordpress生成的查询 编辑:这是上面提到的论坛帖子的代码 在搜索表格中: <input type="hidden" name="post_type" value="page" /> 你可能想在wordpress论坛上看看这个。 您必须在搜索表单中添加一个隐藏表单字段,并添加一个钩子
<input type="hidden" name="post_type" value="page" />
你可能想在wordpress论坛上看看这个。 您必须在搜索表单中添加一个隐藏表单字段,并添加一个钩子来更新wordpress生成的查询 编辑:这是上面提到的论坛帖子的代码 在搜索表格中:
<input type="hidden" name="post_type" value="page" />
在您的search.php中,找到循环并在其后面插入此代码。您可以识别循环,因为它通常以以下内容开始:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
因此,您的代码应该如下所示:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
<?php if (is_search() && ($post->post_type=='post')) continue; ?>
让我知道它是否有效。在您的search.php中,找到循环并在其后面插入此代码。您可以识别循环,因为它通常以以下内容开始:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
因此,您的代码应该如下所示:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
<?php if (is_search() && ($post->post_type=='post')) continue; ?>
让我知道它是否有效