AI Search
Classic Search
 Search Phrase:
 Search Type:
Advanced search options
 Search in Forums:
 Search in date period:

 Sort Search Results by:

AI Assistant
Notifications
Clear all

[Solved] Is there any way to add new posts to the forum programatically?

5 Posts
4 Users
3 Reactions
3,166 Views
WPForoNoob
Posts: 32
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@wpforonoob)
Trusted Member
Joined: 8 years ago
[#10821]

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.


4 Replies
Sofy
Posts: 5777
 Sofy
Admin
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@sofy)
Support Team
Joined: 8 years ago

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. 


1 Reply
WPForoNoob
(@wpforonoob)
Joined: 8 years ago

Trusted Member
Posts: 32
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian

Thanks @sofy 🙂

WPForo is awesome.

 


Posts: 22
 msr
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@msr)
Eminent Member
Joined: 6 years ago

@wpforonoob @tward @sofy

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


1 Reply
Robert
Admin
(@robert)
Joined: 3 months ago

Support Team
Posts: 10753
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian

@msr

Don't search solution to login to wpForo, just search solution for login in WordPress. wpForo authorization is based on WordPress functions, there is no wpForo way to login, once you WordPress you'll be login in wpForo too. So just open a support topic in WordPress support forum or search in WordPress login functions:

https://cleverplugins.com/autologin-wordpress-php-script/


Share: