-
-
Save mypacecreator/b698797511ebaf965c1b70dd420477aa to your computer and use it in GitHub Desktop.
カスタム投稿タイプのカスタムタクソノミー(タグ)をチェックボックスで絞り込み検索
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--カスタム投稿のタグをチェックボックスで絞り込み--> | |
<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