AP_Questions_Widget::widget( array $args, array $instance )

Description #

Widget render

Parameters #

  • $args
    array (Required) Arguments.
  • $instance
    array (Required) Widget arguments.

Source #

File: widgets/questions.php

	public function widget( $args, $instance ) {
		$instance = wp_parse_args(
			$instance,
			array(
				'title'        => __( 'Questions', 'anspress-question-answer' ),
				'order_by'     => 'active',
				'limit'        => 5,
				'category_ids' => '',
			)
		);

		/**
		 * This filter is documented in widgets/question_stats.php
		 */
		$title = apply_filters( 'widget_title', $instance['title'] );

		$order_by     = $instance['order_by'];
		$limit        = $instance['limit'];
		$category_ids = $instance['category_ids'];

		if ( ! empty( $category_ids ) ) {
			$category_ids = explode( ',', str_replace( ' ', '', $category_ids ) );
		}

		echo wp_kses_post( $args['before_widget'] );
		if ( ! empty( $title ) ) {
			echo wp_kses_post( $args['before_title'] . $title . $args['after_title'] );
		}

		$question_args = array(
			'showposts'   => $limit,
			'ap_order_by' => $order_by,
			'paged'       => 1,
		);

		if ( is_array( $category_ids ) && count( $category_ids ) > 0 ) {
			$question_args['tax_query'][] = array(
				'taxonomy' => 'question_category',
				'field'    => 'term_id',
				'terms'    => $category_ids,
			);
		}

		anspress()->questions = ap_get_questions( $question_args );
		echo '<div class="ap-widget-inner">';
		ap_get_template_part( 'widgets/widget-questions' );
		echo '</div>';
		echo wp_kses_post( $args['after_widget'] );

		wp_reset_postdata();
	}

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