Last active
April 25, 2018 10:47
-
-
Save gatespace/8a1e2393d3577f43657bd77a62755e29 to your computer and use it in GitHub Desktop.
[WordPress] ターム(カテゴリー・タグ)の記事が指定件数以下なら一覧などに出力しない ref: https://qiita.com/gatespace/items/efc3792e00e55b50b53c
This file contains hidden or 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
<?php | |
// get_terms でタグに所属する投稿が指定した件数より少なかったら表示しない | |
add_filter( 'get_terms', 'my_get_terms', 10, 4 ); | |
function my_get_terms( $terms, $taxonomies, $args, $term_query ) { | |
if ( is_admin() ) { // 管理画面だったら何もしない | |
return $terms; | |
} | |
if ( $taxonomies[0] != 'post_tag' ) { // 条件分岐はよしなに | |
return $terms; | |
} | |
$new_terms = array(); | |
foreach ( $terms as $term ) { | |
if ( $term->count >= 6 ) { | |
$new_terms[] = $term; | |
} | |
} | |
return $new_terms; | |
} |
This file contains hidden or 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
<?php | |
// get_the_terms でタグに所属する投稿が指定した件数より少なかったら表示しない | |
add_filter( 'get_the_terms', 'my_get_the_terms', 10, 3 ); | |
function my_get_the_terms( $terms, $post_id, $taxonomy ) { | |
if ( is_admin() ) { // 管理画面だったら何もしない | |
return $terms; | |
} | |
if ( $taxonomy != 'post_tag') { // 条件分岐はよしなに | |
return $terms; | |
} | |
$new_terms = array(); | |
foreach ( $terms as $term ) { | |
if ( $term->count >= 6 ) { | |
$new_terms[] = $term; | |
} | |
} | |
return $new_terms; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment