Noptin_Subscriber_Query::parse_orderby( string $orderby )

Parse and sanitize ‘orderby’ keys passed to the subscriber query.


Parameters Parameters

$orderby

(string) (Required) Alias for the field to order by.


Top ↑

Return Return

(string) Value to use in the ORDER clause, if $orderby is valid.


Top ↑

Source Source

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

	protected function parse_orderby( $orderby ) {
		global $wpdb;

		$meta_query_clauses = $this->meta_query->get_clauses();
		$table              = get_noptin_subscribers_table_name();

		$_orderby = '';
		if ( in_array( $orderby, array( 'first_name', 'second_name', 'email', 'date_created', 'active' ) ) ) {
			$_orderby = $orderby;
		} elseif ( 'id' === strtolower( $orderby ) ) {
			$_orderby = 'id';
		} elseif ( 'meta_value' === $orderby || $this->get( 'meta_key' ) == $orderby ) {
			$_orderby = "$wpdb->noptin_subscribermeta.meta_value";
		} elseif ( 'meta_value_num' == $orderby ) {
			$_orderby = "$wpdb->noptin_subscribermeta.meta_value+0";
		} elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) {
			$include     = noptin_parse_int_list( $this->query_vars['include'] );
			$include_sql = implode( ',', $include );
			$_orderby    = "FIELD( $table.id, $include_sql )";
		} elseif ( isset( $meta_query_clauses[ $orderby ] ) ) {
			$meta_clause = $meta_query_clauses[ $orderby ];
			$_orderby    = sprintf( 'CAST(%s.meta_value AS %s)', esc_sql( $meta_clause['alias'] ), esc_sql( $meta_clause['cast'] ) );
		}

		return $_orderby;
	}


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