Notifications
Clear all

wpForo 1.x.x [Solved] How to automatically create a new topic in a forum?

5 Posts
2 Users
1 Reactions
1,273 Views
Posts: 22
 msr
Topic starter
(@msr)
Eminent Member
Joined: 5 years ago

How to automatically create a new topic in a forum, feeding title and content?

4 Replies
Posts: 22
 msr
Topic starter
(@msr)
Eminent Member
Joined: 5 years ago

..and assign its ownership to a specific user

Alvina
Posts: 1863
Moderator
(@alvina)
Member
Joined: 5 years ago

@msr

Please follow Sofy's answer in this support topic:  https://wpforo.com/community/how-to-and-troubleshooting-2/is-there-any-way-to-add-new-posts-to-the-forum-programatically/#post-32888

 

Posts: 22
 msr
Topic starter
(@msr)
Eminent Member
Joined: 5 years ago

Excellent, it works 🙂 Thanks a lot!

Posts: 22
 msr
Topic starter
(@msr)
Eminent Member
Joined: 5 years ago

It turns out it worked when I visited the php file from the browser. When calling the script from code, it does not work.

I am assuming this may have to do with not properly signing in to wpForo, although I do not see any errors. What is the proper way to login to wpForo from code? I have tried adding this code in the script, which seems to signing to WordPress, but creating the topic still does not work when calling the script from code:

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);