LLMS_Database_Query::query()

Execute a query.


Description Description

Overrides the parent to detect if a filter re-added SQL_CALC_FOUND_ROWS to the query, and falls back to FOUND_ROWS() if so.

Also warns when a subclass does not set $this->count_query, which means get_found_results() and get_max_pages() will return 0.


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/abstracts/abstract.llms.database.query.php

	public function query() {

		parent::query();

		$has_sql_calc = ! $this->get( 'suppress_filters' ) &&
			is_string( $this->query ) &&
			str_contains( $this->query, 'SQL_CALC_FOUND_ROWS' );

		if ( $has_sql_calc ) {
			_deprecated_argument(
				"llms_{$this->id}_query_prepare_query",
				'[version]',
				'SQL_CALC_FOUND_ROWS should no longer be added via filters. Results are now counted with a separate COUNT query.'
			);

			global $wpdb;
			$this->found_results = (int) $wpdb->get_var( 'SELECT FOUND_ROWS()' ); // db call ok; no-cache ok.
			$this->max_pages     = absint( ceil( $this->found_results / $this->get( 'per_page' ) ) );
		}

		if (
			$this->number_results &&
			! $this->get( 'no_found_rows' ) &&
			! $this->get( 'count_only' ) &&
			empty( $this->count_query ) &&
			! $has_sql_calc
		) {
			_doing_it_wrong(
				get_class( $this ) . '::prepare_query',
				sprintf(
					/* translators: %s: The query subclass name. */
					'Subclasses of LLMS_Database_Query should set $this->count_query in prepare_query() when no_found_rows is not true. %s does not set count_query, so get_found_results() and get_max_pages() will return 0.',
					get_class( $this )
				),
				'[version]'
			);
		}
	}


Top ↑

Changelog Changelog

Changelog
Version Description
10.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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