1

I've got a custom post type 'Speakers' that, after some time, are added to a custom 'archive' taxonomy so that they can be sorted into different sections of the site.

I'd like a way to hide any posts that have had this category assigned to them when looking at the edit.php post list in admin.

I can display a custom column that shows which posts are 'archived' and I can create a filter that shows all posts which are in the 'archived' category, but I'm having trouble creating the inverse, I.E. a filter which hides all posts of a certain category.

Edit: To clarify, I can already create a user-set filter (like the built-in post date one) that will show only posts that have been assigned the custom taxonomy 'Archived'. All I'm trying to do is create one that will show only posts that have not been assigned to 'Archived'. That is, a way to quickly hide any posts with that taxonomy.

This is the code I've got to make the existing filter. I though that assigning 'show_option_none' in wp_dropdown_categories would do it, but it doesn't seem to have.

add_action('restrict_manage_posts', 'tsm_filter_post_type_by_taxonomy');
function tsm_filter_post_type_by_taxonomy() {
    global $typenow;
    $post_type = 'speakers';
    $taxonomy  = 'archive_status';
    if ($typenow == $post_type) {
    $selected      = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
    $info_taxonomy = get_taxonomy($taxonomy);
    wp_dropdown_categories(array(
        'show_option_all' => __("Show All {$info_taxonomy->label}"),
        'taxonomy'        => $taxonomy,
        'name'            => $taxonomy,
        'orderby'         => 'speaking_date',
        'selected'        => $selected,
        'show_count'      => true,
        'hide_empty'      => true,
    ));
};
}

add_filter('parse_query', 'npc_convert_id_to_term_in_query');

function npc_convert_id_to_term_in_query($query) {
global $pagenow;
$post_type = 'speakers';
$taxonomy  = 'archive_status';
$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;
}
}
  • Hiding anything in admin defeat the purpose of having an admin (if you want to admin one of those posts how do you do it?) – Mark Kaplun Nov 16 '15 at 4:26
  • The idea is that it would be a setting that the user could use, exactly the same as any of the other filters that are already built in ('Show posts from March' etc.). If you wanted to edit a post with that category you would just set the filter to not hide it. – Liam Nov 16 '15 at 4:44
  • sounds like a plan, so what are the exact problem you are running into? please edit the question and add the code that you have tried. – Mark Kaplun Nov 16 '15 at 5:03
  • I've added the edit and the existing code above. – Liam Nov 17 '15 at 3:47

Your Answer

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

Browse other questions tagged or ask your own question.