Noptin_Subscriber_Query::get_search_sql( string $string, array $cols )

Used internally to generate an SQL string for searching across multiple columns


Parameters Parameters

$string

(string) (Required) The string to search for.

$cols

(array) (Required) The columns to search in.


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/class-noptin-subscriber-query.php

	protected function get_search_sql( $string, $cols ) {
		global $wpdb;

		$searches = array();
		$string   = trim( $string, '%' );
		$like     = '%' . $wpdb->esc_like( $string ) . '%';

		foreach ( $cols as $col ) {
			if ( 'id' === $col ) {
				$searches[] = $wpdb->prepare( "$col = %s", $string );
			} else {
				$searches[] = $wpdb->prepare( "$col LIKE %s", $like );
			}
		}

		return ' AND (' . implode( ' OR ', $searches ) . ')';
	}


Top ↑

Changelog Changelog

Changelog
VersionDescription
1.2.7Introduced.

Top ↑

User Contributed Notes User Contributed Notes

30 day money back guarantee
Safe & Secure online payment
Custom CSS Slide Example
Custom Animation Example
Default Animation