最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

some one help . search not jump to search page

programmeradmin1浏览0评论

i have form search :

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

and here is querry in search page

$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_posts() ): ?> have_posts() ) : $the_query->the_post(); ?>

i have form search :

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

and here is querry in search page

$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_posts() ): ?> have_posts() ) : $the_query->the_post(); ?> Share Improve this question asked Oct 26, 2020 at 1:54 Vu DungVu Dung 1
Add a comment  | 

1 Answer 1

Reset to default 1

You’re sending your form directly to homepage. Your form doesn’t have field with name “s” in it.

So there is now way for WordPress to guess, that it should display search results instead of homepage.

发布评论

评论列表(0)

  1. 暂无评论