ap_get_questions_orderby( string $current_url = '' )

Description #

Return all order by options for questions list.

Parameters #

  • $current_url
    string (Optional) Current page URL. Default value: ''

Changelog #

VersionDescription
3.0.0Introduced.

Source #

File: includes/theme.php

function ap_get_questions_orderby( $current_url = '' ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
	$param    = array();
	$search_q = get_query_var( 'ap_s' );

	if ( ! empty( $search_q ) ) {
		$param['ap_s'] = $search_q;
	}

	$navs = array(
		array(
			'key'   => 'order_by',
			'value' => 'active',
			'label' => __( 'Active', 'anspress-question-answer' ),
		),
		array(
			'key'   => 'order_by',
			'value' => 'newest',
			'label' => __( 'New', 'anspress-question-answer' ),
		),
	);

	if ( ! ap_opt( 'disable_voting_on_question' ) ) {
		$navs[] = array(
			'key'   => 'order_by',
			'value' => 'voted',
			'label' => __( 'Votes', 'anspress-question-answer' ),
		);
	}

	$navs[] = array(
		'key'   => 'order_by',
		'value' => 'answers',
		'label' => __( 'Answers', 'anspress-question-answer' ),
	);
	$navs[] = array(
		'key'   => 'order_by',
		'value' => 'views',
		'label' => __( 'Views', 'anspress-question-answer' ),
	);
	$navs[] = array(
		'key'   => 'order_by',
		'value' => 'solved',
		'label' => __( 'Solved', 'anspress-question-answer' ),
	);
	$navs[] = array(
		'key'   => 'order_by',
		'value' => 'unanswered',
		'label' => __( 'Unanswered', 'anspress-question-answer' ),
	);
	$navs[] = array(
		'key'   => 'order_by',
		'value' => 'unsolved',
		'label' => __( 'Unsolved', 'anspress-question-answer' ),
	);

	foreach ( (array) $navs as $k => $args ) {
		$active = ap_get_current_list_filters( 'order_by' );

		if ( $active === $args['value'] ) {
			$navs[ $k ]['active'] = true;
		}
	}

	/**
	 * Filter question sorting.
	 *
	 * @param array $navs Questions orderby list.
	 * @since 2.3
	 */
	return apply_filters( 'ap_questions_order_by', $navs );
}

2 Comments

  1. Aakash Hanumant Kambale November 10, 2022 at 11:20 am

    How to remove unsolved filter option.

    let me know

    Reply
  2. Aakash Hanumant Kambale November 14, 2022 at 5:29 pm

    function remove_unsolved_filter( $navs ) {

    $new = array();
    foreach ( $navs as $key => $filter ) {
    if( $filter[‘value’] != ‘unsolved’ ){
    $new[] = $filter;
    }
    }

    return $new;
    }
    add_filter( ‘ap_questions_order_by’, ‘remove_unsolved_filter’ );

    Solved………………………………………………………………………………………………

    Reply

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