ap_get_category_filter( string|boolean $search = false )

Description #

Return category for sorting dropdown.

Parameters #

  • $search
    string | boolean (Optional) Search value. Default value: false

Source #

File: includes/taxo.php

function ap_get_category_filter( $search = false ) {
	$args = array(
		'taxonomy'      => 'question_category',
		'hierarchical'  => true,
		'hide_if_empty' => true,
		'number'        => 10,
	);

	if ( false !== $search ) {
		$args['search'] = $search;
	}

	$terms    = get_terms( $args );
	$selected = ap_get_current_list_filters( 'category' );

	if ( ! $terms ) {
		return false;
	}

	$items = array();

	foreach ( (array) $terms as $t ) {
		$item = array(
			'key'   => 'category',
			'value' => (string) $t->term_id,
			'label' => $t->name,
		);
		// Check if active.
		if ( $selected && in_array( $t->term_id, $selected, true ) ) {
			$item['active'] = true;
		}

		$items[] = $item;
	}

	return $items;
}

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