Add Elementor event loop preset library and separate releases
This commit is contained in:
@@ -360,7 +360,7 @@ final class Events {
|
||||
public static function query( array $filters ): array {
|
||||
global $wpdb;
|
||||
$table = self::table();
|
||||
$filters += [ 'from' => null, 'to' => null, 'past' => false, 'search' => '', 'category' => '', 'tag' => '', 'location' => '', 'relation' => null, 'scope' => '', 'featured' => false, 'offset' => 0, 'limit' => 20 ];
|
||||
$filters += [ 'from' => null, 'to' => null, 'end_by' => null, 'past' => false, 'order' => '', 'search' => '', 'category' => '', 'tag' => '', 'location' => '', 'relation' => null, 'relations' => [], 'scope' => '', 'featured' => false, 'exclude' => 0, 'offset' => 0, 'limit' => 20 ];
|
||||
$where = [ "p.post_type = 'burn_event'", "p.post_status = 'publish'", "p.post_password = ''" ];
|
||||
$where[] = "NOT EXISTS (SELECT 1 FROM $wpdb->postmeta h WHERE h.post_id = p.ID AND h.meta_key = '_burn_hidden' AND h.meta_value = '1')";
|
||||
if ( '' !== $filters['scope'] ) {
|
||||
@@ -372,27 +372,43 @@ final class Events {
|
||||
if ( $filters['to'] ) {
|
||||
$where[] = $wpdb->prepare( $filters['past'] ? 'o.ends_at <= %s' : 'o.starts_at < %s', $filters['to'] );
|
||||
}
|
||||
if ( $filters['end_by'] ) {
|
||||
$where[] = $wpdb->prepare( 'o.ends_at <= %s', $filters['end_by'] );
|
||||
}
|
||||
if ( $filters['exclude'] ) {
|
||||
$where[] = $wpdb->prepare( 'p.ID <> %d', $filters['exclude'] );
|
||||
}
|
||||
if ( $filters['search'] ) {
|
||||
$like = '%' . $wpdb->esc_like( $filters['search'] ) . '%';
|
||||
$where[] = $wpdb->prepare( '(p.post_title LIKE %s OR p.post_content LIKE %s)', $like, $like );
|
||||
}
|
||||
foreach ( [ 'category' => self::CATEGORY, 'tag' => 'post_tag' ] as $key => $taxonomy ) {
|
||||
if ( $filters[ $key ] ) {
|
||||
$where[] = $wpdb->prepare( "EXISTS (SELECT 1 FROM $wpdb->term_relationships r JOIN $wpdb->term_taxonomy tt ON tt.term_taxonomy_id = r.term_taxonomy_id JOIN $wpdb->terms t ON t.term_id = tt.term_id WHERE r.object_id = p.ID AND tt.taxonomy = %s AND t.slug = %s)", $taxonomy, $filters[ $key ] );
|
||||
$slugs = array_values( (array) $filters[ $key ] );
|
||||
$placeholders = implode( ', ', array_fill( 0, count( $slugs ), '%s' ) );
|
||||
$where[] = $wpdb->prepare( "EXISTS (SELECT 1 FROM $wpdb->term_relationships r JOIN $wpdb->term_taxonomy tt ON tt.term_taxonomy_id = r.term_taxonomy_id JOIN $wpdb->terms t ON t.term_id = tt.term_id WHERE r.object_id = p.ID AND tt.taxonomy = %s AND t.slug IN ($placeholders))", $taxonomy, ...$slugs );
|
||||
}
|
||||
}
|
||||
$relations = array_intersect_key( $filters['relations'], self::RELATIONS );
|
||||
if ( $filters['relation'] ) {
|
||||
[ $type, $id ] = $filters['relation'];
|
||||
$where[] = $wpdb->prepare( "EXISTS (SELECT 1 FROM $wpdb->postmeta m WHERE m.post_id = p.ID AND m.meta_key = %s AND m.meta_value = %s)", '_burn_' . $type, (string) $id );
|
||||
$relations[ $type ] = [ (string) $id ];
|
||||
}
|
||||
foreach ( $relations as $type => $ids ) {
|
||||
if ( $ids ) {
|
||||
$placeholders = implode( ', ', array_fill( 0, count( $ids ), '%s' ) );
|
||||
$where[] = $wpdb->prepare( "EXISTS (SELECT 1 FROM $wpdb->postmeta m WHERE m.post_id = p.ID AND m.meta_key = %s AND m.meta_value IN ($placeholders))", '_burn_' . $type, ...array_values( $ids ) );
|
||||
}
|
||||
}
|
||||
if ( $filters['location'] ) {
|
||||
$like = '%' . $wpdb->esc_like( $filters['location'] ) . '%';
|
||||
$where[] = $wpdb->prepare( "EXISTS (SELECT 1 FROM $wpdb->postmeta m LEFT JOIN $wpdb->posts v ON m.meta_key = '_burn_venue' AND v.ID = CAST(m.meta_value AS UNSIGNED) AND v.post_status = 'publish' LEFT JOIN $wpdb->postmeta a ON a.post_id = v.ID AND a.meta_key = '_burn_address' WHERE m.post_id = p.ID AND (v.post_title LIKE %s OR a.meta_value LIKE %s OR (m.meta_key = '_burn_search_location' AND m.meta_value LIKE %s)))", $like, $like, $like );
|
||||
}
|
||||
if ( $filters['featured'] ) {
|
||||
$where[] = "EXISTS (SELECT 1 FROM $wpdb->postmeta f WHERE f.post_id = p.ID AND f.meta_key = '_burn_featured' AND f.meta_value = '1')";
|
||||
$featured = "EXISTS (SELECT 1 FROM $wpdb->postmeta f WHERE f.post_id = p.ID AND f.meta_key = '_burn_featured' AND f.meta_value = '1')";
|
||||
$where[] = 'regular' === $filters['featured'] ? 'NOT ' . $featured : $featured;
|
||||
}
|
||||
$order = $filters['past'] ? 'DESC' : 'ASC';
|
||||
$order = in_array( $filters['order'], [ 'ASC', 'DESC' ], true ) ? $filters['order'] : ( $filters['past'] ? 'DESC' : 'ASC' );
|
||||
$limit = $wpdb->prepare( ' LIMIT %d OFFSET %d', $filters['limit'], $filters['offset'] );
|
||||
return $wpdb->get_results( "SELECT o.event_id, o.starts_at, o.ends_at FROM $table o JOIN $wpdb->posts p ON p.ID = o.event_id WHERE " . implode( ' AND ', $where ) . " ORDER BY o.starts_at $order, o.event_id $order" . $limit, ARRAY_A ) ?: [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user