Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $exclusive_post_type = 'book';
- $exclude_cats = array();
- $nonemptycats = get_terms( 'category' );
- foreach( $nonemptycats as $term ){
- $term_id = $term->term_id;
- $term_objects = get_objects_in_term( $term_id, 'category' );
- $exclude_term = true;
- foreach( $term_objects as $post_id ){
- if ( $exclusive_post_type === get_post_type( $post_id ) ){
- $exclude_term = false;
- break;
- }
- }
- if ( $exclude_term ) $exclude_cats[] = $term_id;
- }
- $args = array(
- 'orderby' => 'name',
- 'show_count' => false,
- 'hide_if_empty' => true,
- 'show_option_all' => 'All categories',
- 'depth' => 1,
- 'exclude' => $exclude_cats,
- );
- ?>
- Categories: <?php wp_dropdown_categories( $args ); ?>
Advertisement
Add Comment
Please, Sign In to add comment