• LifterLMS
  • Knowledge Base
  • Academy
  • Blog
  • Podcast
  • Contributors

LifterLMS LifterLMS

Code Reference

  • Home
  • Code Reference
Skip to content
Filter by type:
Search
Browse: Home / Code Reference / Classes / LLMS_Query_User_Postmeta / LLMS_Query_User_Postmeta::sql_where()

LLMS_Query_User_Postmeta::sql_where()

SQL “where” clause for the query

Contents

  • Description
    • Return
    • Source
    • Changelog
  • Related
    • Used By
  • User Contributed Notes

Description #Description


Return #Return

(string)


Top ↑

Source #Source

File: includes/class.llms.query.user.postmeta.php

	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' )} ";
				}

				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;

				}
			}

			$sql .= ' )';

		}// End if().

		return apply_filters( $this->get_filter( 'where' ), $sql, $this );

	}

Expand full source code Collapse full source code View on GitHub


Top ↑

Changelog #Changelog

Changelog
Version Description
3.15.0 Introduced.

Top ↑

Related #Related

Top ↑

Used By #Used By

Used By
Used By Description
includes/class.llms.query.user.postmeta.php: LLMS_Query_User_Postmeta::preprare_query()

Prepare the SQL for the query


Top ↑

User Contributed Notes #User Contributed Notes

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

© 2014 - 2019 LifterLMS · Privacy Policy · Terms and Conditions