From 0d7a4542ef0c0114ae9788c83df80993449b18ce Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 29 Jan 2023 15:40:18 +0100 Subject: Add filters to shortcode concert table. --- includes/giglogadmin-shortcodes.php | 13 ++++++++++-- includes/templates/giglogadmin-concerts-table.php | 26 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/includes/giglogadmin-shortcodes.php b/includes/giglogadmin-shortcodes.php index 053e297..8e410b2 100644 --- a/includes/giglogadmin-shortcodes.php +++ b/includes/giglogadmin-shortcodes.php @@ -22,11 +22,20 @@ if ( ! function_exists( 'giglogadmin_shortcode_public' ) ) { * This shortcode does not have any attributes. */ function giglogadmin_shortcode_public() : string { - $opts = array( + $filters = array( 'offset' => 0, 'limit' => 15, ); - $concerts = GiglogAdmin_Concert::find_concerts( $opts ); + + if ( isset( $_GET['city'] ) && ! empty( $_GET['city'] ) ) { + $filters['city'] = sanitize_text_field( wp_unslash( $_GET['city'] ) ); + } + + if ( isset( $_GET['venue'] ) && ! empty( $_GET['venue'] ) ) { + $filters['venue'] = sanitize_text_field( wp_unslash( $_GET['venue'] ) ); + } + + $concerts = GiglogAdmin_Concert::find_concerts( $filters ); ob_start(); include __DIR__ . '/templates/giglogadmin-concerts-table.php'; diff --git a/includes/templates/giglogadmin-concerts-table.php b/includes/templates/giglogadmin-concerts-table.php index f5ca911..93f5366 100644 --- a/includes/templates/giglogadmin-concerts-table.php +++ b/includes/templates/giglogadmin-concerts-table.php @@ -26,6 +26,32 @@ }
+
+ + Filters + +
+ array( $c, $c ), GiglogAdmin_Venue::all_cities() ), + $filters['city'] ?? null, + 'City' + ); + + // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped + echo EternalTerror\ViewHelpers\select_field( + 'venue', + array_map( fn( $v ) => array( $v->name(), "{$v->name()}, {$v->city()}" ), GiglogAdmin_Venue::all_venues() ), + $filters['venue'] ?? null, + 'Venue' + ); + ?> + + Clear filters +
+
-- cgit v1.2.3