AnsPress_Reputation_Query::query()

Description #

Prepare and fetch reputations from database.

Source #

File: includes/reputation.php

	private function query() {
		global $wpdb;

		$order    = 'DESC' === $this->args['order'] ? 'DESC' : 'ASC';
		$excluded = sanitize_comma_delimited( $this->with_zero_points, 'str' );

		$not_in = '';
		if ( ! empty( $excluded ) ) {
			$not_in = " AND rep_event NOT IN({$excluded})";
		}

		$query = $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS * FROM {$wpdb->ap_reputations} WHERE rep_user_id = %d{$not_in} ORDER BY rep_date {$order} LIMIT %d,%d", $this->args['user_id'], $this->offset, $this->per_page ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared

		$result            = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB
		$this->total_count = $wpdb->get_var( apply_filters( 'ap_reputations_found_rows', 'SELECT FOUND_ROWS()', $this ) ); // phpcs:ignore WordPress.DB
		$this->reputations = $result;
		$this->total_pages = ceil( $this->total_count / $this->per_page );
		$this->count       = count( $result );
		$this->prefetch();
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment