0

I unregistered a custom taxonomy form the theme I'm using:

function wpse314876_unregister_taxonomy() {
    unregister_taxonomy_for_object_type( 'page_category', 'page' );
}
add_action( 'init', 'wpse314876_unregister_taxonomy' );

But in the all pages overview (/wp-admin/edit.php?post_type=page) it shows still an empty drop-down filter list. I can remove all category drop-down but that's not what I want as I already added a custom drop-down taxonomy filter-list.

The drop-down appears as a little empty list empty list and its HTML looks like that:

<select name="page_category" id="page_category" class="postform">
</select>

How can I remove just what empty drop-down list?

0

After I little digging I found the right action in the parent theme. The function looked like that (actually exactly the example I linked above):

//////////////////////////////
// Add page category filter //
//////////////////////////////

add_action('restrict_manage_posts', 'uncode_page_filter_post_type_by_taxonomy');

function uncode_page_filter_post_type_by_taxonomy() {
    global $typenow;
    $post_type = 'page'; // change to your post type
    $taxonomy  = 'page_category'; // change to your taxonomy
    if ($typenow == $post_type) {
        $selected      = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
        $info_taxonomy = get_taxonomy($taxonomy);
        wp_dropdown_categories(array(
            'show_option_all' => sprintf(esc_html__("Show All %s", 'uncode'), $info_taxonomy->label),
            'taxonomy'        => $taxonomy,
            'name'            => $taxonomy,
            'orderby'         => 'name',
            'selected'        => $selected,
            'show_count'      => true,
            'hide_empty'      => true,
        ));
    };
}

add_filter('parse_query', 'uncode_page_convert_id_to_term_in_query');
function uncode_page_convert_id_to_term_in_query($query) {
    global $pagenow;
    $post_type = 'page'; // change to your post type
    $taxonomy  = 'page_category'; // change to your taxonomy
    $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;
    }
}

Solution

To remove them I added a simple remove_action() to my child-theme function.php.

/**
 * Remove page_category filter and parse query
 *
 **/
remove_action('restrict_manage_posts', 'uncode_page_filter_post_type_by_taxonomy');
remove_action('parse_query', 'uncode_page_convert_id_to_term_in_query');
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.