bbp_update_reply_topic_id( int $reply_id, int $topic_id )

Update the reply with its topic id it is in


Description Description


Parameters Parameters

$reply_id

(Optional) Reply id to update

$topic_id

(Optional) Topic id


Top ↑

Return Return

(bool) The topic id of the reply


Top ↑

Source Source

File: includes/replies/functions.php

function bbp_update_reply_topic_id( $reply_id = 0, $topic_id = 0 ) {

	// Validation
	$reply_id = bbp_get_reply_id( $reply_id );
	$topic_id = bbp_get_topic_id( $topic_id );

	// If no topic_id was passed, walk up ancestors and look for topic type
	if ( empty( $topic_id ) ) {

		// Get ancestors
		$ancestors = (array) get_post_ancestors( $reply_id );

		// Loop through ancestors
		if ( ! empty( $ancestors ) ) {
			foreach ( $ancestors as $ancestor ) {

				// Get first parent that is a topic
				if ( get_post_field( 'post_type', $ancestor ) === bbp_get_topic_post_type() ) {
					$topic_id = $ancestor;

					// Found a topic, so exit the loop and continue
					continue;
				}
			}
		}
	}

	// Update the topic ID
	$retval = bbp_update_topic_id( $reply_id, $topic_id );

	// Filter & return
	return (int) apply_filters( 'bbp_update_reply_topic_id', $retval, $reply_id, $topic_id );
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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