Skip to content

Commit

Permalink
Allow multiple categories to be used in ESPRESSO_EVENTS (#3125)
Browse files Browse the repository at this point in the history
* Switch to sanitize_text_field() so that dashes aren't stripped from the categories passed.

* Build out $event_category_slugs_array from whatever is passed and trim each element in the array to remove whitespaces

Use $event_category_slugs_array to build out an placeholder string to be used with prepare. (Count the number of slugs and add N number of placeholders to a string)

Switch to use IN in the SQL query and pass both $event_category_slugs_prepare and $event_category_slugs_array to prepare.

* Add braces around $event_category_slugs_prepare

* Style fixes.
  • Loading branch information
Pebblo authored Sep 17, 2020
1 parent 1e722e0 commit 311299c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions core/helpers/EEH_Event_Query.helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private static function _display_month($month = '')
*/
private static function _event_category_slug($category = '')
{
return sanitize_title_with_dashes(EE_Registry::instance()->REQ->get('event_query_category', $category));
return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_category', $category));
}


Expand Down Expand Up @@ -541,9 +541,12 @@ public static function posts_where_sql_for_show_expired($show_expired = false)
public static function posts_where_sql_for_event_category_slug($event_category_slug = null)
{
global $wpdb;
return ! empty($event_category_slug)
? $wpdb->prepare(" AND {$wpdb->terms}.slug = %s ", $event_category_slug)
: '';
if (! empty($event_category_slug)) {
$event_category_slugs_array = array_map('trim', explode(',', $event_category_slug));
$event_category_slugs_prepare = implode(', ', array_fill(0, count($event_category_slugs_array), '%s'));
return $wpdb->prepare(" AND {$wpdb->terms}.slug IN ({$event_category_slugs_prepare}) ", $event_category_slugs_array);
}
return '';
}


Expand Down

0 comments on commit 311299c

Please sign in to comment.