WordPress.org

Support

Support » How-To and Troubleshooting » Assign Custom List Type to Custom Post Type

Assign Custom List Type to Custom Post Type

  • TCBarrett
    Member

    @tcbarrett

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • lpointet
    Member

    @lpointet

    Tom,

    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.
    Lionel

    TCBarrett
    Member

    @tcbarrett

    Thanks Lionel

    I’ve hidden the filter as follows:

    PHP

    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;
      endif;
    
      return $classes;
    }

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

    TCBarrett
    Member

    @tcbarrett

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Assign Custom List Type to Custom Post Type’ is closed to new replies.