Categories::modify_query_category_archive( array $posts, object $query )

Description #

Modify main query.

Parameters #

  • $posts
    array (Required) Array of post object.
  • $query
    object (Required) Wp_Query object.

Changelog #

VersionDescription
4.1.0Introduced.

Source #

File: addons/categories/categories.php

	public function modify_query_category_archive( $posts, $query ) {
		if ( $query->is_main_query() && $query->is_tax( 'question_category' ) && 'category' === get_query_var( 'ap_page' ) ) {
			$query->found_posts   = 1;
			$query->max_num_pages = 1;
			$page                 = get_page( ap_opt( 'categories_page' ) );

			if ( ! $page ) {
				return $posts;
			}

			$page->post_title = get_queried_object()->name;
			$posts            = array( $page );
		}

		return $posts;
	}

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