BP_REST_Topics_Actions_Endpoint::dropdown_items( WP_REST_Request $request )

Topic’s Dropdown

Description

Parameters

$request

(Required) Full details about the request.

Return

(WP_REST_Response) | WP_Error

Source

File: bp-forums/classes/class-bp-rest-topics-actions-endpoint.php

	public function dropdown_items( $request ) {

		$topic_id = $request->get_param( 'id' );
		$parent   = bbp_get_topic_forum_id( $topic_id );
		$page     = $request->get_param( 'page' );
		$per_page = $request->get_param( 'per_page' );

		$topics_query = new WP_Query(
			array(
				'post_type'          => bbp_get_topic_post_type(),
				'post_status'        => 'publish',
				'post__not_in'       => array( $topic_id ),
				'post_parent'        => $parent,
				'posts_per_page'     => $per_page,
				'paged'              => $page,
				'orderby'            => 'menu_order title',
				'order'              => 'ASC',
				'disable_categories' => true,
			)
		);

		$topics = $topics_query->posts;

		if ( empty( $topics ) ) {
			$retval = new WP_Error(
				'bp_rest_no_other_topics',
				__( 'No discussions available', 'buddyboss' ),
				array(
					'status' => 404,
				)
			);
		}

		foreach ( $topics as $topic ) {
			$data[] = array(
				'id'    => $topic->ID,
				'title' => array(
					'raw'      => $topic->post_title,
					'rendered' => bbp_get_topic_title( $topic->ID ),
				),
			);
		}

		$response = rest_ensure_response( $data );
		$response = bp_rest_response_add_total_headers( $response, $topics_query->found_posts, $per_page );

		/**
		 * Fires after a list of topics is fetched via the REST API.
		 *
		 * @param array            $topics   Fetched Topics.
		 * @param WP_REST_Response $response The response data.
		 * @param WP_REST_Request  $request  The request sent to the API.
		 *
		 * @since 0.1.0
		 */
		do_action( 'bp_rest_topics_dropdown_items', $topics, $response, $request );

		return $response;
	}

Changelog

Changelog
Version Description
0.1.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.