bp_get_thread( array|string $args = '' )

Initialize the messages template loop for a specific thread and sets thread.

Description

Parameters

$args

(Optional) Array of arguments. All are optional.

  • 'thread_id'
    (int) ID of the thread whose messages you are displaying. Default: if viewing a thread, the thread ID will be parsed from the URL (bp_action_variable( 0 )).
  • 'order'
    (string) 'ASC' or 'DESC'. Default: 'ASC'.
  • 'update_meta_cache'
    (bool) Whether to pre-fetch metadata for queried message items. Default: true.

Default value: ''

Return

(object) thread template.

Source

File: bp-messages/bp-messages-template.php

function bp_get_thread( $args = '' ) {
	global $thread_template;

	$r = bp_parse_args( $args, array(
		'thread_id'         => false,
		'order'             => 'DESC',
		'update_meta_cache' => true,
	), 'thread_has_messages' );

	if ( empty( $r['thread_id'] ) && bp_is_messages_component() && bp_is_current_action( 'view' ) ) {
		$r['thread_id'] = (int) bp_action_variable( 0 );
	}

	// Set up extra args.
	$extra_args = $r;
	unset( $extra_args['thread_id'], $extra_args['order'] );

	$thread_template = new BP_Messages_Thread_Template( $r['thread_id'], $r['order'], $extra_args );

	return $thread_template;
}

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.