自定义搜索产品定制帖子类型
我准备了一个产品的自定义帖子。我想包含一个表单,只有几个筛选器可供搜索。因为我正在做第一次搜索。我的产品模板是不同的,并希望在页面或特定div中显示其结果。这怎么可能。我有点困惑。以下是我的表单字段。自定义搜索产品定制帖子类型
<form role="search" method="get" id="searchform" action="<?php echo home_url('/'); ?>">
<div class="row">
<div class="col-md-3">Search Keyword:</div>
<div class="col-md-3"><input type="text" placeholder="Search Product..."></div>
<div class="col-md-2"><input type="submit" id="searchsubmit" value="Searchi"></div>
</div>
<div class="row">
<lable for="r1"><input type="radio" name="product-filter" id="r1" checked="chcecked"> Any Words</lable>
<lable for="r2"><input type="radio" name="product-filter" id="r2"> All Words</lable>
<lable for="r3"><input type="radio" name="product-filter" id="r3"> Exact Phrase</lable>
</div>
<em>Search term must be a minimum of 3 characters and a maximum of 20 characters</em>
</form>
通过自定义文章类型蛞蝓在隐藏
杆状类型名称:产品
<form role="search" method="get" id="searchform" action="<?php echo esc_url(get_permalink(1)); ?>">
<div class="row">
<div class="col-md-3">Search Keyword:</div>
<div class="col-md-3"><input type="text" placeholder="Search Product..."></div>
<div class="col-md-2"><input type="submit" id="searchsubmit" value="Searchi"> <input type="hidden" name="post_type" value="products"></div>
</div>
<div class="row">
<lable for="r1"><input type="radio" name="product-filter" id="r1" checked="chcecked"> Any Words</lable>
<lable for="r2"><input type="radio" name="product-filter" id="r2"> All Words</lable>
<lable for="r3"><input type="radio" name="product-filter" id="r3"> Exact Phrase</lable>
</div>
<em>Search term must be a minimum of 3 characters and a maximum of 20 characters</em>
</form>
以下是搜索表单按您的指导下代码。
<form role="search" method="get" id="searchform" action="<?php echo home_url('/'); ?>">
<label>
<span class="screen-reader-text">Search for:</span>
<input type="text" placeholder="Search Product...">
<input type="submit" id="searchsubmit" value="Search">
<input type="hidden" name="post_type" value="product">
</label>
</form>
以下是形式
<?php if (have_posts()) : ?>
<h2 class="page-content-title">Search results for: <?php echo get_search_query(); ?></h2>
<div class="container">
<?php while (have_posts()) : the_post(); ?>
<div class="blog-page-content">
<?php if (has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail($post_id, 'medium', array('class' => 'img-responsive')); ?></a>
<?php else : ?>
<?php endif; ?>
<h2><a href="<?php the_permalink(); ?>" class="category-title-link"><?php the_title(); ?></a></h2>
<h6 class="article-meta-extra">
<?php if (has_category() && !has_category('Uncategorized')) : ?>
<?php the_category(' | '); ?> |
<?php else : ?>
<?php endif; ?>
Posted on <?php the_date(get_option('date_format')); ?> at <?php the_time(get_option('time_format')); ?> by <?php the_author_posts_link(); ?>
</h6>
<?php the_excerpt(); ?>
<a href="<?php the_permalink(); ?>" class="btn btn-blue btn-block">Read More</a>
</div><!-- END EACH BLOG-->
<?php endwhile; ?>
<?php else : ?>
<article class="no-posts"><h1>No posts were found.</h1></article>
<?php endif; ?>
</div>
<div class="article-nav clearfix">
<p class="article-nav-next pull-right"><?php previous_posts_link(__('Newer Posts »')); ?></p>
<p class="article-nav-prev pull-left"><?php next_posts_link(__('« Older Posts')); ?></p>
</div>
下方的搜索结果的问题是,它始终显示的结果。我的自定义帖子名称是没有s的'产品'。
什么是您的自定义帖子类型?产品或产品?以及“产品目录”页面的页面标识是什么。转到admin-> pages->编辑“product-directory”并复制浏览器url的页面id。没有S的 –
产品是我的自定义帖子 –
好的。什么是你的“产品目录”页面ID? –
http://www.graymarkdesigns.com/ssa/product-directory/这是我的页面...我已将代码放回到模板文件中。并添加了一个search.php文件。但是当我提交它时,它将我引导到主页 –
更改操作 to –
请检查更新后的答案 –