谁来帮帮忙。搜索不跳转到搜索页面

时间:2020-10-26 作者:Vu Dung

我有表单搜索:

<form action="<?php echo esc_url( home_url( \'/\' ) ); ?>" method="GET" role="form" class="searchform"> 
        <div class="row">
          <div class="col-md-3">
            <input type="hidden" name="post_type" value="tourdl"> 
            <div class="item">
              <label><img src="<?php bloginfo(\'stylesheet_directory\');?>/assets/images/search-1.png" class="img-fluid" alt="">Nơi khởi hành</label>
              <input type="search" name ="noi_kh" placeholder="<?php echo esc_attr_x( \'Search &hellip;\', \'placeholder\' ); ?>">
            </div>
          </div>
          <div class="col-md-3">
            <div class="item">
              <label><img src="<?php bloginfo(\'stylesheet_directory\');?>/assets/images/search-2.png" class="img-fluid" alt="">Điểm đến</label>
              <input type="search" name ="den" placeholder="Nhập nơi đến ...">
            </div>
          </div>
          <div class="col-md-3">
            <div class="item">
              <label><img src="<?php bloginfo(\'stylesheet_directory\');?>/assets/images/search-3.png" class="img-fluid" alt="">Ngày khởi hành</label>
             
              <div class="form-group">
                    <div class=\'input-group date date-book\' id=\'datetimepicker2\'>
                      <input type=\'search\' name="ngay_kh" placeholder="Ngày / tháng / năm" class="inp_date" />
                      <span class="input-group-addon"></span>
                    </div>
                </div>
            </div> 
          </div>
          <div class="col-md-3">
            <div class="item">
              <button type="submit" class="text-uppercase btn-search" id="searchsumit" value="<?php echo esc_attr_x( \'Search\', \'submit button\' ); ?>">Tìm kiếm</button>
            </div>
          </div>
        </div>
    </form>
这里是搜索页面中的querry

$post_type  = isset($_GET[\'post_type\']) && $_GET[\'post_type\'] ? $_GET[\'post_type\'] : \'post\';
$di     = isset($_GET[\'noi_kh\']) && $_GET[\'noi_kh\'] ? $_GET[\'noi_kh\'] : \'\';
$den    = isset($_GET[\'den\']) && $_GET[\'den\'] ? $_GET[\'den\'] : \'\';
$nkh = isset($_GET[\'ngay_kh\']) && $_GET[\'ngay_kh\'] ? $_GET[\'ngay_kh\'] : \'\';
$args = array(
    \'showposts\'     => 10,
    \'post_type\'     => $post_type,
    \'meta_query\'    => array(
        \'relation\'      => \'AND\',
        array(
            \'key\'      => \'noi_khoi_hanh\',
            \'value\'     => $di,   
            \'compare\'   => \'Like\'
        ),
        array(
            \'key\'      => \'diem_den\',
            \'value\'     => $den,   
            \'compare\'   =>\'Like\'
        ),
         array(
            \'key\'       => \'ngay_khoi_hanh\',
            \'value\'     =>  $nkh,
            \'type\'      => \'datetimepicker2\',
            \'compare\'   => \'Like\',   
        )
    ),
);
&燃气轮机;

have\\u posts()):?>have\\u posts()):$the\\u query->the\\u post();?>

1 个回复
SO网友:Krzysiek Dróżdż

您正在将表单直接发送到主页。表单中没有名为“s”的字段。

所以WordPress现在可以猜测,它应该显示搜索结果而不是主页。

相关推荐

search based on custom field

我的问题是,有没有办法将wordpress的搜索配置为在自定义帖子类型中搜索自定义字段值。//------------html code--------------------// <input type=\"text\" name=\"keyword\" id=\"keyword\" onkeyup=\"fetch()\"></input> <div id=\"datafetch\"></div> &#x