WordPress:固定ページにカスタムタクソノミーとカスタム投稿のキーワード(タイトル・本文)で絞り込み検索する方法

 

page-search.php

 

<ul id="fq">
<?php
$search_str = $_GET['key'];
$faq_tax = $_GET['cat'];

$data_array = array(
    'post_type' => 'faq',
    'posts_per_page' => -1,
    's' => $search_str,

  );

if (!empty($faq_tax)){
  $taxquery = $data_array;
  $taxquery['tax_query'] = array(
    array(
    'taxonomy' => 'faq_taxonomy',
    'field' => 'slug',
    'terms' => $faq_tax
    )
  );

} else {
  $taxquery = $data_array;
}

$args = $taxquery;

$my_posts = get_posts($args);
if (!empty($my_posts)): foreach($my_posts as $post): setup_postdata($post);

?>
  <li class="qa"><a href="<?php the_permalink(); ?>"><?php the_title();?></a></li>
<?php endforeach; wp_reset_postdata(); endif;  ?>
</ul>

 

 

 

 

category cloud