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/giglogadmin-shortcodes.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/giglogadmin-shortcodes.php')
-rw-r--r-- | includes/giglogadmin-shortcodes.php | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/includes/giglogadmin-shortcodes.php b/includes/giglogadmin-shortcodes.php index 5a3d70d..1fba82e 100644 --- a/includes/giglogadmin-shortcodes.php +++ b/includes/giglogadmin-shortcodes.php @@ -22,15 +22,27 @@ if ( ! function_exists( 'giglogadmin_shortcode_public' ) ) { * This shortcode does not have any attributes. */ function giglogadmin_shortcode_public() : string { - $filters = array( - 'offset' => 0, - 'limit' => 15, - ); + $filters = array(); if ( isset( $_GET['city'] ) && ! empty( $_GET['city'] ) ) { $filters['city'] = sanitize_text_field( wp_unslash( $_GET['city'] ) ); } + $pages = GiglogAdmin_Concert::count_pages( $filters ); + $page = 1; + + if ( isset( $_GET['pg'] ) && ! empty( $_GET['pg'] ) ) { + $page = intval( wp_unslash( $_GET['pg'] ) ); + + if ( $page < 1 || $page > $pages ) { + // Just silently redirect to first page if we're outside + // the acceptable range. + wp_redirect( get_page_link() ); + } + } + + $filters['page'] = $page; + $concerts = GiglogAdmin_Concert::find_concerts( $filters ); ob_start(); |