AnsPress_Tag::ap_tags_suggestion()

Description #

Handle tags suggestion on question form

Source #

File: addons/free/tag.php

	public static function ap_tags_suggestion() {
		$keyword = ap_sanitize_unslash( 'q', 'r' );

		$tags = get_terms( 'question_tag', array(
			'orderby'    => 'count',
			'order'      => 'DESC',
			'hide_empty' => false,
			'search'     => $keyword,
			'number'     => 8,
		));

		if ( $tags ) {
			$items = array();
			foreach ( $tags as $k => $t ) {
				$items [ $k ] = $t->slug;
			}

			$result = array( 'status' => true, 'items' => $items );
			wp_send_json( $result );
		}

		wp_send_json( array( 'status' => false ) );
	}

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