[워드프레스] 커스텀 카테고리 필터하기 (스니펫) - 하나몬
Mon Nov 21 2022 08:22:05 GMT+0000 (Coordinated Universal Time)
Saved by
@ncia
// 관리자에 사용자 지정 분류 드롭 다운 표시
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;
}
}
content_copyCOPY
https://hanamon.kr/워드프레스-커스텀-카테고리-필터-스니펫/
Comments