上記にしたがってやった
プラグイン+functionに追加する
検索の部分は
<form role="search" method="get" id="searchform" action="<?php echo esc_url(home_url('/')); ?>">
<h2>カテゴリー</h2>
<?php
$category_args = array(
'orderby' => 'name',
'order' => 'ASC',
);
$categories = get_terms( 'category', $category_args );
foreach($categories as $category) :
?>
<label><input type="checkbox" name="get_cats[]" value="<?php echo $category->slug; ?>"><?php echo $category->name; ?></label>
<?php endforeach; ?>
<h2>タグ</h2>
<?php
$post_tag_args = array(
'orderby' => 'name',
'order' => 'ASC',
);
$post_tags = get_terms( 'post_tag', $post_tag_args );
foreach($post_tags as $post_tag) :
?>
<label><input type="checkbox" name="get_tags[]" value="<?php echo $post_tag->slug; ?>"><?php echo $post_tag->name; ?></label>
<?php endforeach; ?>
<h2><?php _x( 'Search for:', 'label' ); ?>キーワード</h2>
<input type="text" value="<?php echo get_search_query(); ?>" name="s" id="s" placeholder="キーワードを入力してください" />
<input type="submit" value="検索" />
</form>
検索結果 serch.phpをごっそり以下にコピペ
<?php
/**
* The template for displaying search results pages.
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
*
* @package wpindex
*/
get_header(); ?>
<section id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
$s = $_GET['s'];
$get_cats = $_GET['get_cats'];
$get_tags = $_GET['get_tags'];
if($get_cats) {
$tax_ary[] = array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $get_cats,
'operator' => 'IN', //ANDかIN
);
}
if($get_tags) {
$tax_ary[] = array(
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => $get_tags,
'operator' => 'IN', //ANDかIN
);
}
?>
<?php if (!($s || $get_cats || $get_tags)): ?>
<p>検索条件を指定してください</p>
<?php get_search_form(); ?>
<?php else: ?>
<h1>検索結果</h1>
<?php
if(is_array($get_cats)) {
echo '<p>カテゴリー:';
foreach ($get_cats as $val) {
$p_term = get_term_by('slug', $val, 'category');
echo $p_term->name;
if ($val !== end($get_cats)) {
echo ', ';
}
}
echo '</p>';
} ?>
<?php
if(is_array($get_tags)) {
echo '<p>タグ:';
foreach ($get_tags as $val) {
$s_term = get_term_by('slug', $val, 'post_tag');
echo $s_term->name;
if ($val !== end($get_tags)) {
echo ', ';
}
}
echo '</p>';
} ?>
<?php
if($s) { echo '<p>キーワード:'.$s.'</p>'; } ?>
<?php
$my_query = new WP_Query( array(
'paged' => get_query_var('paged'),
'post_type' => 'post',
'tax_query' => $tax_ary,
'relation' => 'AND', //ANDかOR
's' => $s,
)); ?>
<?php if($my_query->have_posts() ) : ?>
<ul>
<?php while( $my_query->have_posts()) : $my_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
<?php else: ?>
<p>結果が見つかりませんでした。</p>
<?php endif; ?>
<?php endif; ?>
</main><!-- #main -->
</section><!-- #primary -->
<?php
get_sidebar();
get_footer();