2017-06-15 15 views
0

商品のカスタムポストを準備しました。私は検索のためのフィルタがほとんどないフォームを含める必要があります。私が最初に検索しているように。私の製品テンプレートは異なり、その結果をページ内または特定の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> 

答えて

0

ポストタイプ名のように隠された

でカスタムポストタイプのスラッグを渡す:製品

<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> 
+0

http://www.graymarkdesigns.com/ssa/product-directory/これは私のページです...コードをテンプレートファイルに戻しました。 search.phpファイルを追加しました。しかし私がそれを提出すると、それは私をホームページに案内します –

+0

アクションを変更します <?php echo home_url( '/'); ?>?<?php echo get_page_link( 'product-directory'); ?> –

+0

更新された回答を確認してください –

0

以下のご指導どおり検索フォームのコードです。次

<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> 

下の検索結果です。私のカスタム投稿名は「商品」です。

+0

あなたのカスタムポストタイプは何ですか?製品または製品? 「製品ディレクトリ」ページのページIDは何ですか。 admin-> pages-> "product-directory"を編集し、ブラウザのURLのページIDをコピーしてください。 –

+0

Sなしの商品は私のカスタムポストです –

+0

okです。あなたの "製品ディレクトリ"のページIDはどのIDですか? –

関連する問題