LLMS_Admin_Post_Table_Lessons::parse_query_filters( WP_Query $query )

Modify the main WP Query


Parameters Parameters

$query

(WP_Query) (Required) The WordPress Query.


Top ↑

Return Return

(WP_Query)


Top ↑

Source Source

File: includes/admin/post-types/post-tables/class.llms.admin.post.table.lessons.php

	public function parse_query_filters( $query ) {

		// Only modify admin & main query.
		if ( ! ( is_admin() && $query->is_main_query() ) ) {
			return $query;
		}

		// Don't proceed if it's not our post type.
		if ( ! isset( $query->query['post_type'] ) || 'lesson' !== $query->query['post_type'] ) {
			return $query;
		}

		// If none of our custom filters are set, don't proceed.
		if ( ! isset( $_REQUEST['llms_filter_course_id'] ) ) {
			return $query;
		}

		// Get the query or a default to work with.
		$meta_query = $query->get( 'meta_query' );
		if ( ! $meta_query ) {
			$meta_query = array();
		}

		/**
		 * Set an and relation for our filters
		 * if other filters already exist, we'll ensure we obey them as well this way.
		 */
		$meta_query['relation'] = 'AND';

		$meta_query[] = array(
			'compare' => '=',
			'key'     => '_llms_parent_course',
			'value'   => absint( $_REQUEST['llms_filter_course_id'] ),
		);

		$query->set( 'meta_query', $meta_query );

		return $query;

	}

Top ↑

Changelog Changelog

Changelog
Version Description
4.5.1 Bail early if the query has no post_type property set.
3.12.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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