Assign Custom List Type to Custom Post Type (4 posts)

  1. TCBarrett
    Posted 4 years ago #

    I have a custom post type where the 'filter by post date' does not make sense. Posts by default use WP_List_Table which calls extra_tablenav() from display_tablenav() without any filters (that I can see) to stop this behaviour.

    Would it be possible to extend the class to rework display_tablenav() and the make WP use that list table instead? If so, where do I start this?

    Ideally I'd be able to add some headers in there as well as remove the date filter.

  2. lpointet
    Posted 3 years ago #


    One way of doing it is to "hide" that filter (with CSS) or remove it with JS. Indeed, you can easily add an extra class to the body with 'admin_body_class' filter (depending on the $pagenow and $post_type global vars for example) to only target your CPT list.

    To add one or more filters after those included by WordPress, you can use the 'restrict_manage_posts' action.

    Unfortunately, I think that John is right on that, you cannot extend the list table classes for now.

    Hope that helps.

  3. TCBarrett
    Posted 3 years ago #

    Thanks Lionel

    I've hidden the filter as follows:


    add_filter( 'admin_body_class', 'tcb_admin_body_class' );
    function tcb_admin_body_class( $classes ){
      $screen = get_current_screen();
      if( is_array($classes) ) :
        $classes[] = $screen->post_type;
      else :
        $classes .= ' ' . $screen->post_type;
      return $classes;

    jQuery('body.post-type .tablenav.top .actions:nth-child(1)').hide();

  4. TCBarrett
    Posted 3 years ago #

    Unfortunately, output from the 'restrict_manage_posts' action also gets hidden by the above code. Ho hum.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.