LLMS_Events_Query::sql_where()

SQL “where” clause for the query


Return Return

(string)


Top ↑

Source Source

File: includes/class-llms-events-query.php

163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
protected function sql_where() {
 
    global $wpdb;
 
    $sql = 'WHERE 1';
 
    // "IN" clauses for id fields.
    $ids_include = array(
        'actor'   => 'actor_id',
        'object'  => 'object_id',
        'include' => 'id',
    );
    foreach ( $ids_include as $query_key => $db_key ) {
        $ids = $this->get( $query_key );
        if ( $ids ) {
            $prepared = implode( ',', $ids );
            $sql     .= " AND {$db_key} IN ({$prepared})";
        }
    }
 
    // "NOT IN" clauses for id fields.
    $ids_exclude = array(
        'actor_not_in'  => 'actor_id',
        'object_not_in' => 'object_id',
        'exclude'       => 'id',
    );
    foreach ( $ids_exclude as $query_key => $db_key ) {
        $ids = $this->get( $query_key );
        if ( $ids ) {
            $prepared = implode( ',', $ids );
            $sql     .= " AND {$db_key} NOT IN ({$prepared})";
        }
    }
 
    // Matching fields.
    $matching = array( 'object_type', 'event_type', 'event_action' );
    foreach ( $matching as $key ) {
        $val = $this->get( $key );
        if ( $val ) {
            $sql .= sprintf( " AND {$key} = '%s'", esc_sql( $val ) );
        }
    }
 
    // Date fields.
    $before = $this->get( 'date_before' );
    if ( $before ) {
        $sql .= $wpdb->prepare( ' AND date < %s', $before );
    }
 
    $after = $this->get( 'date_after' );
    if ( $after ) {
        $sql .= $wpdb->prepare( ' AND date > %s', $after );
    }
 
    if ( $this->get( 'suppress_filters' ) ) {
        return $sql;
    }
 
    /**
     * Filters the query WHERE clause
     *
     * @since 3.36.0
     *
     * @param string            $sql          The WHERE clause of the query.
     * @param LLMS_Events_Query $events_query Instance of LLMS_Events_Query.
     */
    return apply_filters( 'llms_events_query_where', $sql, $this );
 
}


Top ↑

Changelog Changelog

Changelog
Version Description
4.7.0 Drop usage of $this->get_filter('where') in favor of 'llms_events_query_where'.
3.36.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.