WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. TCBarrett
    Member
    Posted 1 year 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
    Member
    Posted 1 year ago #

    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

  3. TCBarrett
    Member
    Posted 1 year ago #

    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();

  4. TCBarrett
    Member
    Posted 1 year 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

Tags

No tags yet.