bbp_insert_forum( array $forum_data = array(), arrap $forum_meta = array() )

A wrapper for wp_insert_post() that also includes the necessary meta values for the forum to function properly.

Description

Parameters

$forum_data

(array) (Optional) Forum post data

Default value: array()

$forum_meta

(arrap) (Optional) Forum meta data

Default value: array()

Source

File: bp-forums/forums/functions.php

function bbp_insert_forum( $forum_data = array(), $forum_meta = array() ) {

	// Forum
	$forum_data = bbp_parse_args( $forum_data, array(
		'post_parent'    => 0, // forum ID
		'post_status'    => bbp_get_public_status_id(),
		'post_type'      => bbp_get_forum_post_type(),
		'post_author'    => bbp_get_current_user_id(),
		'post_password'  => '',
		'post_content'   => '',
		'post_title'     => '',
		'menu_order'     => 0,
		'comment_status' => 'closed'
	), 'insert_forum' );

	// Insert forum
	$forum_id   = wp_insert_post( $forum_data );

	// Bail if no forum was added
	if ( empty( $forum_id ) ) {
		return false;
	}

	// Forum meta
	$forum_meta = bbp_parse_args( $forum_meta, array(
		'reply_count'          => 0,
		'topic_count'          => 0,
		'topic_count_hidden'   => 0,
		'total_reply_count'    => 0,
		'total_topic_count'    => 0,
		'last_topic_id'        => 0,
		'last_reply_id'        => 0,
		'last_active_id'       => 0,
		'last_active_time'     => 0,
		'forum_subforum_count' => 0,
	), 'insert_forum_meta' );

	// Insert forum meta
	foreach ( $forum_meta as $meta_key => $meta_value ) {
		update_post_meta( $forum_id, '_bbp_' . $meta_key, $meta_value );
	}

	// Return new forum ID
	return $forum_id;
}

Changelog

Changelog
Version Description
bbPress (r3349) 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.