get_related_table_name(); $limit = $per_page; $page = max( 1, $page ); $table = [ [ $table, 't' ], [ [ $this->get_wp_table( 'posts' ), 'p' ], 'INNER JOIN', [ 't.post_id', '=', 'p.ID', ], ], ]; empty( $where ) and $where = []; if ( $is_valid ) { $where['p.post_status'] = 'publish'; } $total = $this->app->db->select_count( $table, null, $where ); $total_page = isset( $per_page ) ? ceil( $total / $per_page ) : 1; $page = min( $total_page, $page ); $offset = isset( $per_page ) && isset( $page ) ? $per_page * ( $page - 1 ) : null; $list = $this->app->db->select( $table, $where, null, $limit, $offset, $orderby ); if ( empty( $list ) ) { return [ 'total' => 0, 'total_page' => 0, 'page' => $page, 'data' => [], ]; } $post_ids = $this->app->utility->array_pluck( $list, 'post_id' ); $posts = get_posts( [ 'include' => $post_ids, 'post_type' => $instance->get_post_type(), 'post_status' => 'any', ] ); $posts = $this->app->utility->array_combine( $posts, 'ID' ); return [ 'total' => $total, 'total_page' => $total_page, 'page' => $page, 'data' => array_map( function ( $d ) use ( $posts, $instance ) { return $instance->filter_callback( 'filter_item', [ $instance->filter_callback( 'set_post_data', [ $d, $posts[ $d['post_id'] ] ] ) ] ); }, $list ), ]; } }