Skip to content

Instantly share code, notes, and snippets.

@yujiokayama
Last active January 15, 2018 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yujiokayama/ecb2a8be669e314f1563307fa7cf75d3 to your computer and use it in GitHub Desktop.
Save yujiokayama/ecb2a8be669e314f1563307fa7cf75d3 to your computer and use it in GitHub Desktop.
カスタム投稿タイプのカスタムタクソノミー(タグ)をチェックボックスで絞り込み検索
<!--カスタム投稿のタグをチェックボックスで絞り込み-->
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>">
<label for="s" class="assistive-text">検索</label>
<h2>タグまたはカスタムタクソノミー</h2>
<?php
$taxonomy_name = 'cpt_tag';
$taxonomys = get_terms($taxonomy_name);
if(!is_wp_error($taxonomys) && count($taxonomys)):
foreach($taxonomys as $taxonomy):
$tax_posts = get_posts(array('post_type' => get_post_type('cpttype'), 'taxonomy' => $taxonomy_name, 'term' => $taxonomy->slug ) );
if($tax_posts):
?>
<label><input type="checkbox" name="cpt_tag[]" value="<?php echo $taxonomy->slug; ?>"><?php echo $taxonomy->name; ?></label><br>
<?php endif; endforeach; endif;
wp_reset_postdata();?>
<input type="submit" value="検索" />
</form>
<!--//カスタム投稿のタグをチェックボックスで絞り込み-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment