// 관리자에 사용자 지정 분류 드롭 다운 표시
add_action('restrict_manage_posts', 'artwork_filter_custom_post_type_by_taxonomy');
function artwork_filter_custom_post_type_by_taxonomy() {
global $typenow;
$post_type = 'artwork'; // 게시물 유형 변경
$taxonomy = 'artwork-category'; // 분류법 변경
if ($typenow == $post_type) {
$selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
$info_taxonomy = get_taxonomy($taxonomy);
wp_dropdown_categories(array(
'show_option_all' => sprintf( __( '모든 %s', 'textdomain' ), $info_taxonomy->label ),
'taxonomy' => $taxonomy,
'name' => $taxonomy,
'orderby' => 'name',
'selected' => $selected,
'show_count' => true,
'hide_empty' => true,
));
};
}
// 관리자에서 분류별로 게시물 필터링
add_filter('parse_query', 'artwork_convert_id_to_term_in_query');
function artwork_convert_id_to_term_in_query($query) {
global $pagenow;
$post_type = 'artwork'; // 게시물 유형 변경
$taxonomy = 'artwork-category'; // 분류법 변경
$q_vars = &$query->query_vars;
if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0 ) {
$term = get_term_by('id', $q_vars[$taxonomy], $taxonomy);
$q_vars[$taxonomy] = $term->slug;
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter