bbp_get_topic_engagements_raw( int $topic_id )

Return the users who have engaged in a topic, directly with a database query


Description Description

See: https://bbpress.trac.wordpress.org/ticket/3083


Parameters Parameters

$topic_id

(Required)


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/users/engagements.php

function bbp_get_topic_engagements_raw( $topic_id = 0 ) {

	// Default variables
	$topic_id = bbp_get_topic_id( $topic_id );
	$bbp_db   = bbp_db();
	$statii   = "'" . implode( "', '", bbp_get_public_topic_statuses() ) . "'";

	// A cool UNION query!
	$sql = "
SELECT DISTINCT( post_author ) FROM (
	SELECT post_author FROM {$bbp_db->posts}
		WHERE ( ID = %d AND post_status IN ({$statii}) AND post_type = %s )
UNION
	SELECT post_author FROM {$bbp_db->posts}
		WHERE ( post_parent = %d AND post_status = %s AND post_type = %s )
) as u1";

	// Prepare & get results
	$query   = $bbp_db->prepare( $sql, $topic_id, bbp_get_topic_post_type(), $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type() );
	$results = $bbp_db->get_col( $query );

	// Parse results into voices
	$engagements = ! is_wp_error( $results )
		? wp_parse_id_list( array_filter( $results ) )
		: array();

	// Filter & return
	return (array) apply_filters( 'bbp_get_topic_engagements_raw', $engagements, $topic_id );
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.