Hi team,
Is there a way to make this work: https://wpforo.com/community/general-discussions/sticky-topics-order-updated-function/
For simple (not threaded) forums and sub-forums?
Thanks, A
Hi @fastertomaster,
There is no a general solution for all places, it depends on the forum layout and the page (home forum list or in forum topic list). Please specify an exact layout and an exact page.
Hi @fastertomaster,
For the Simplified forum layout you can use this code in the current active WordPress theme functions.php file. If you have an active WordPress child theme, you should only use the child theme functions.php file. Once you put this code and saved. Go to Dashboard > Forums > Dashboard and click on the [Delete All Caches] button.
function wpforo_custom_sticky_topic_order( $current_object, $wpf_url_parse ){
$rules = array();
//$rules[ ForumID ] = array( First TopicID, Second TopicID );
$rules[4] = array(19, 6);
$rules[7] = array(26, 63, 68);
if( function_exists('WPF') && isset($current_object['template']) ){
if( $current_object['template'] == 'topic' && wpfval($current_object, 'topics') ){
$topics = $current_object['topics'];
$tmp = array(); $ordered = array();
$forumid = $current_object['forumid'];
if( !empty( $rules ) && isset( $rules[$forumid] ) ){
foreach( $topics as $key => $topic ){if( isset($topic['topicid'])) {$tmp[$topic['topicid']] = $topic;}}
if( !empty($tmp) ){foreach( $rules[$forumid] as $topicid ){if( isset($tmp[$topicid]) ) {$ordered[] = $tmp[$topicid]; unset($tmp[$topicid]);}}}
$topics = array_merge($ordered, $tmp);
$topics = array_values($topics);
if(!empty($topics)) $current_object['topics'] = $topics;
}
}
}
return $current_object;
}
add_filter('wpforo_after_init_current_object', 'wpforo_custom_sticky_topic_order', 10, 2);
This is the part where you should edit and change forum/topic IDs. For example, you want to set topicid 19 first, then topicid 6 second in forumid 4 you should add/edit the row this way:
$rules[4] = array(19, 6);
If you don't have other forums where you want to add sticky topic ordering rules just remove the second line. I added this to show you can add as much $rules as you want:
$rules[7] = array(26, 63, 68);
Works perfectly. Thank you for the awesome continued support.
Review left on the plugin page:
https://wordpress.org/support/topic/superb-support-77/#new-topic-0
Thank you!
Hello,