LLMS_Events_Query::sql_where()
SQL “where” clause for the query
Return Return
(string)
Source Source
File: includes/class-llms-events-query.php
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 );
}
Expand full source code Collapse full source code View on GitHub
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. |