Thank you @robin-w!
But what should I enter specifically?
Event type: PHP cron event
Hook name: bbpress_topic_scheduler, bbpress_daily_event, or bbpress_close_old_topics?
arguments: ?
next run: now, tomorrow, a specific time
repeat: once, hourly, twicedaily, daily or weekly?
I just want to make sure I do everything right
ok, so delete the previous code and put this code instead
function bbpress_close_old_topics() {
// Auto close old topics
$topics_query = array(
'author' => 0,
'show_stickies' => false,
'parent_forum' => 'any',
'post_status' => 'publish',
'posts_per_page' => -1
);
if ( bbp_has_topics( $topics_query ) )
while( bbp_topics() ) {
bbp_the_topic();
$topic_id = bbp_get_topic_id();
$topic_date = strtotime( get_post( $topic_id, 'post_date', true ) );
$forum_id = bbp_get_topic_forum_id($topic_id);
if ($topic_date < strtotime( '-2 hours') ) // && $forum_id == 1276 )
bbp_close_topic( $topic_id );
}
}
In other words we take out the cron scheduling functions from the code
then
Event type: PHP cron event
Hook name: bbpress_close_old_topics
arguments: none
next run: now
repeat: hourly
That should do it, you should see it as an event.
If you have a topic already set to expire, it should do so immediately as you have schgeduled to run ‘now and then every hour’ in the above.
Thank you for the reply @robin-w 🙂
When I select PHP cron event, should I enter the code in there and delete the snippet? Because when I click PHP cron event, a code editor will open.
I can only say try it – sorry I am limited in time I can give free to things 🙂
keep playing and you should be able to work it out.
Otherwise would be paid effort – contact me via http://www.rewweb.co.uk/contact-me/
I get the following error using the code in my functions.php file
PHP Warning: strtotime() expects parameter 1 to be string, object given
the line cited in the above warning is
$topic_date = strtotime( get_post( $topic_id, 'post_date', true ) );
so can you post the entire code you are using please
<?php
register_activation_hook(__FILE__, ‘bbpress_topic_scheduler’);
add_action(‘bbpress_daily_event’, ‘bbpress_delete_old_topics’);
function bbpress_topic_scheduler() {
wp_schedule_event(time(), ‘daily’, ‘bbpress_daily_event’);
}
function bbpress_delete_old_topics() {
// Auto delete old topics
$topics_query = array(
‘author’ => 0,
‘show_stickies’ => false,
‘parent_forum’ => ‘any’,
‘post_status’ => ‘publish’,
‘posts_per_page’ => -1
);
if ( bbp_has_topics( $topics_query ) )
while( bbp_topics() ) {
bbp_the_topic();
$topic_id = bbp_get_topic_id();
$topic_date = strtotime( get_post( $topic_id, ‘post_date’, true ) );
$forum_id = bbp_get_topic_forum_id($topic_id);
if ($topic_date = strtotime( ‘-90 days’) && $forum_id == 17777 )
bbp_delete_topic( $topic_id ); }
}
?>