LLMS_Query_User_Postmeta::sql_where()
SQL “where” clause for the query
Return Return
(string)
Source Source
File: includes/class.llms.query.user.postmeta.php
* @since 3.15.0
* @version 3.15.0
*/
protected function sql_where() {
global $wpdb;
$sql = 'WHERE 1';
foreach ( array( 'post_id', 'user_id' ) as $key ) {
$ids = $this->get( $key );
if ( $ids ) {
$prepared = implode( ',', $ids );
$sql .= " AND {$key} IN ({$prepared})";
}
}
if ( $this->get( 'query' ) ) {
$sql .= ' AND ( ';
foreach ( $this->get( 'query' ) as $i => $query ) {
if ( 0 !== $i ) {
$sql .= " {$this->get( 'query_compare' )} ";
}
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
switch ( $query['compare'] ) {
case '=':
case '!=':
case 'LIKE':
$sql .= $wpdb->prepare( "( meta_key = %s AND meta_value {$query['compare']} %s )", $query['key'], $query['value'] );
break;
case 'IN':
case 'NOT IN':
$query['value'] = array_map( array( $this, 'escape_and_quote_string' ), $query['value'] );
$vals = implode( ',', $query['value'] );
$sql .= $wpdb->prepare( "( meta_key = %s AND meta_value {$query['compare']} ( {$vals} ) )", $query['key'] );
break;
case 'IS NOT NULL':
$sql .= $wpdb->prepare( "( meta_key = %s AND meta_value {$query['compare']} )", $query['key'] );
break;
}
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
}
$sql .= ' )';
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 3.15.0 | Introduced. |