Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* https://ja.wordpress.org/support/topic/ループ内で、親と子カテゴリーを選択したとき、/ */
- function my_category_list( $categories, $post_id ) {
- $cats = $categories;
- $cats_ID = array_map( function ( $cat ) {
- return $cat->term_id;
- }, $cats );
- foreach ( $categories as $key => $category ) {
- $ancestor = $category;
- while ( ! empty( $ancestor->parent ) && $ancestor = get_category( $ancestor->parent ) ) {
- if ( in_array( $ancestor->term_id, $cats_ID, true ) ) {
- unset( $cats[ $key ] );
- break;
- }
- }
- }
- return $cats;
- }
- add_filter( 'the_category_list', 'my_category_list', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement