LoginSignup
2
3

More than 5 years have passed since last update.

wpの検索結果URLを固定ページにする

Last updated at Posted at 2017-03-25

ここでは一覧用の固定ページはpage-list.php

<form action="/list/" method="get">
<!-- valueはキーワードがあるかどうかの判定 -->
<input name="keyword" value="<?php echo isset($_GET['keyword']))? esc_html($_GET['keyword']) : ''; ?>">
</form>
page-list.php
<?php
$args = array(
  'post_type' => array('hoge','foo'),
  'posts_per_page' => -1,
);
// キーワードがあるかどうか
if(isset($_GET['keyword'])) $args['s'] = esc_html($_GET['keyword']);
$the_query = new WP_Query( $args );
// ループ
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
  // 何かする
endwhile;
endif;
// 投稿データをリセット
wp_reset_postdata();
?>

たぶんこういうイメージかな。。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3