diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2023-03-07 22:36:21 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2023-03-07 22:36:21 +0100 |
commit | a12086e6813f4a526ccbafbb32713c963258479c (patch) | |
tree | e680add56ee4b9335c45cddded1025c8fcc0099a /includes/class-giglogadmin-concert.php | |
parent | 1c6be6b8a5724f5a4162168241062abded4635e7 (diff) | |
download | gigologadmin-a12086e6813f4a526ccbafbb32713c963258479c.tar.gz gigologadmin-a12086e6813f4a526ccbafbb32713c963258479c.tar.bz2 gigologadmin-a12086e6813f4a526ccbafbb32713c963258479c.zip |
Add links + pagination to concerts table shortcode.
Diffstat (limited to 'includes/class-giglogadmin-concert.php')
-rw-r--r-- | includes/class-giglogadmin-concert.php | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/includes/class-giglogadmin-concert.php b/includes/class-giglogadmin-concert.php index a470617..c6223cb 100644 --- a/includes/class-giglogadmin-concert.php +++ b/includes/class-giglogadmin-concert.php @@ -211,6 +211,8 @@ if ( ! class_exists( 'GiglogAdmin_Concert' ) ) { $where = array(); $offset = 0; $limit = 15; + $page = null; + foreach ( $filter as $key => $value ) { switch ( $key ) { case 'name': @@ -230,6 +232,10 @@ if ( ! class_exists( 'GiglogAdmin_Concert' ) ) { array_push( $where, $keymap[ $key ] . $wpdb->prepare( ' like %s', esc_like( $value ) ) ); break; + case 'page': + $page = intval( $value ); + break; + case 'offset': $offset = intval( $value ); break; @@ -244,6 +250,10 @@ if ( ! class_exists( 'GiglogAdmin_Concert' ) ) { $query .= ' AND ' . implode( ' and ', $where ); } + if ( $page !== null ) { + $offset = ( $page - 1 ) * $limit; + } + $query .= ' ORDER BY wpgconcert_date'; $query .= " LIMIT {$offset},{$limit}"; @@ -290,6 +300,22 @@ if ( ! class_exists( 'GiglogAdmin_Concert' ) ) { } /** + * Return number of pages with the limit of concerts/page + * specified in the filter. + * + * @param array<string, mixed> $filter The filter to use for the query. + * @return number of pages. + */ + public static function count_pages( array $filter = array() ) : int { + if ( ! isset( $filter['limit'] ) ) { + $filter['limit'] = 15; + } + + $num_concerts = self::count( $filter ); + return ( intval( $num_concerts / $filter['limit'] ) ) + 1; + } + + /** * Save concert to database. */ public function save() : void { |