AnsPress_Admin::serach_qa_by_userid( object $query )

Description #

Add author args in query.

Parameters #

  • $query
    object (Required) WP_Query object.

Source #

File: admin/anspress-admin.php

	public static function serach_qa_by_userid( $query ) {
		$screen = get_current_screen();

		if ( isset( $query->query_vars['s'], $screen->id, $screen->post_type ) &&
			( ( 'edit-question' === $screen->id && 'question' === $screen->post_type ) || ( 'edit-answer' === $screen->id && 'answer' === $screen->post_type ) ) &&
			$query->is_main_query() ) {
			$search_q = ap_parse_search_string( get_search_query() );

			// Set author args.
			if ( ! empty( $search_q['author_id'] ) && is_array( $search_q['author_id'] ) ) {
				$user_ids = '';

				foreach ( (array) $search_q['author_id'] as $id ) {
					$user_ids .= (int) $id . ',';
				}

				set_query_var( 'author', rtrim( $user_ids, ',' ) );
			} elseif ( ! empty( $search_q['author_name'] ) && is_array( $search_q['author_name'] ) ) {
				$author_names = array();

				foreach ( (array) $search_q['author_name'] as $id ) {
					$author_names[] = sanitize_title_for_query( $id );
				}
				set_query_var( 'ap_author_name', $author_names );
			}

			set_query_var( 's', $search_q['q'] );
		}
	}

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