Skip to content

Instantly share code, notes, and snippets.

@gvgvgvijayan
Created January 17, 2021 03:55
Show Gist options
  • Select an option

  • Save gvgvgvijayan/be44c43a1f59db909ab7afc9c0de8086 to your computer and use it in GitHub Desktop.

Select an option

Save gvgvgvijayan/be44c43a1f59db909ab7afc9c0de8086 to your computer and use it in GitHub Desktop.

Revisions

  1. gvgvgvijayan created this gist Jan 17, 2021.
    47 changes: 47 additions & 0 deletions prepare_items.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    <?php
    ...
    /**
    * Prepare the data for the WP List Table
    *
    * @return void
    */
    public function prepare_items() {
    $columns = $this->get_columns();
    $sortable = $this->get_sortable_columns();
    $hidden = array();
    $primary = 'title';
    $this->_column_headers = array( $columns, $hidden, $sortable, $primary );
    $data = array();

    $this->process_bulk_action();

    $get_posts_obj = $this->get_posts_object();

    if ( $get_posts_obj->have_posts() ) {

    while ( $get_posts_obj->have_posts() ) {

    $get_posts_obj->the_post();

    $data[ get_the_ID() ] = array(
    'id' => get_the_ID(),
    'title' => get_the_title(),
    'type' => ucwords( get_post_type_object( get_post_type() )->labels->singular_name ),
    'date' => get_post_datetime(),
    'author' => get_the_author(),
    );
    }
    wp_reset_postdata();
    }

    $this->items = $data;

    $this->set_pagination_args(
    array(
    'total_items' => $get_posts_obj->found_posts,
    'per_page' => $get_posts_obj->post_count,
    'total_pages' => $get_posts_obj->max_num_pages,
    )
    );
    }
    ...