BuddyPress::page_answers( false|int $user_id = false, bool $paged = false, false|string $order_by = false, bool $only_posts = false )

Description #

Callback for rendering questions page.

Parameters #

  • $user_id
    false | int (Optional) Id of user. Default value: false
  • $paged
    bool (Optional) Is currently paged. Default value: false
  • $order_by
    false | string (Optional) Order by column. Default value: false
  • $only_posts
    bool (Optional) Show only posts. Default value: false

Source #

File: addons/buddypress/buddypress.php

	public function page_answers( $user_id = false, $paged = false, $order_by = false, $only_posts = false ) {
		global $answers;

		$order_by                       = false === $order_by ? 'active' : $order_by;
		$args['ap_current_user_ignore'] = true;
		$args['ignore_selected_answer'] = true;
		$args['showposts']              = 10;
		$args['author']                 = bp_displayed_user_id();
		$args['ap_order_by']            = ap_sanitize_unslash( 'order_by', 'r', $order_by );

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

		/**
		 * FILTER: ap_authors_questions_args
		 * Filter authors question list args
		 *
		 * @var array
		 */
		$args    = apply_filters( 'ap_bp_answers_args', $args );
		$answers = new \Answers_Query( $args );

		anspress()->answers = $answers;

		if ( false === $only_posts ) {
			echo '<div class="ap-bp-head clearfix">';
			echo '<h1>' . esc_attr__( 'Answers', 'anspress-question-answer' ) . '</h1>';
			ap_answers_tab( get_the_permalink() );
			echo '</div>';
			echo '<div id="ap-bp-answers">';
		}

		if ( ap_have_answers() ) {
			/* Start the Loop */
			while ( ap_have_answers() ) :
				ap_the_answer();
				ap_get_template_part( 'buddypress/answer-item' );
			endwhile;
		}

		if ( false === $only_posts ) {
			echo '</div>';
		}

		if ( $answers->max_num_pages > 1 && false === $only_posts ) {
			$args = wp_json_encode(
				array(
					'__nonce'  => wp_create_nonce( 'loadmore-answers' ),
					'type'     => 'answers',
					'current'  => 1,
					'user_id'  => bp_displayed_user_id(),
					'order_by' => ap_sanitize_unslash( 'order_by', 'r' ),
				)
			);
			echo '<a href="#" class="ap-bp-loadmore ap-btn" ap-loadmore="' . esc_js( $args ) . '">' . esc_attr__( 'Load more answers', 'anspress-question-answer' ) . '</a>';
		}
	}

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