Limited Support
Our support team is currently on holiday from December 25, 2025 to January 7, 2026, and replies may be delayed during this period.
We appreciate your patience and understanding while our team is away. Thank you for being part of the wpForo community!
Merry Christmas and Happy Holidays! 🎄
Hi,
I was wondering if WPForo has some functions similar to `wp_update_post()` and `wp_insert_post()` which can be used to add forum topics programatically.
Thanks.
Hi @wpforonoob,
Below is provided the codes that add a topics and posts in the forum. You just need to change red marked codes before using:
$topic = array(
'userid' => USERID,
'title' => TITLE,
'body' => BODY,
'forumid' => FORUMID,
'views' => VIEWS,
'type' => TYPE,
'created' => CREATED
);
WPF()->topic->add($topic);
$reply = array(
'userid' => USERID,
'title' => TITLE,
'body' => BODY,
'topicid' => TOPICID,
'created' => CREATED
);
WPF()->post->add($reply);
The arrays below contain only required arguments. If you need to insert additional arguments just get the fields name from the following tables:
- wp_wpforo_posts
- wp_wpforo_topics
the wp_ is just a prefix. In your case it can differ.
If you open the topic and post classes you'll find all methods you want to use.
Did anyone manage to do this from a cron job or similar code not already logged in? I tried adding the following code, and although it seems to login the user to wordpress, the topic is not made. I am assuming there is some login issue. How to properly login to wpForo?
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
$user_login = 'admin';
$user = get_userdatabylogin($user_login);
$user_id = $user->ID;
wp_set_current_user($user_id, $user_login);
wp_set_auth_cookie($user_id);
do_action('wp_login', $user_login);