Notifications
Clear all

Shortcodes for Multi-boards

5 Posts
2 Users
1 Likes
453 Views
Posts: 4
Topic starter
(@cloud9)
Active Member
Joined: 6 months ago

Use Case

I'm using LifertLMS to deliver training material for multiple courses, wpForo to facilitate discussion & Ultimate Member to show/hide blocks/content/pages. I have created separate boards for each course. The structure of each board is exacly the same including the IDs of each category and forum. For example the FAQ topic has the ID = 3 in each board. Each forum maps to a single lesson topic.

On each lesson page I want to include only the forum that is relevant to that lesson based on the course being viewed. So I use the shortcode system e.g.

[wpforo item="forum" id="3"]

If the user is on a page that is part of course 1 then I want the FAQ topic from board 1 to show. If the user is on a page from course 2 then I want the FAQ topic from board 2 to show.

Problem

According to the documentation, the shortcode doesn't have an option to specify the board so the forum with ID = 3 is always from the first board.

Question

How do I specify which board to source the requested forum from? If there is no current way to do this I'm happy to make a copy of the plugin and make temporary changes where indicated.

wpForo Version
2.1.5
WordPress Version
6.1
4 Replies
Posts: 4
Topic starter
(@cloud9)
Active Member
Joined: 6 months ago

I tried this in functions.php:

function set_wpForo_board() {
  if ( !is_admin() ) {
    // Only target the front end
    WPF()->change_board(2);
  }
}
add_action( 'the_post', 'set_wpForo_board');
 
The board ID changes but has no effect on the shortcode.
Reply
Posts: 4
Topic starter
(@cloud9)
Active Member
Joined: 6 months ago

The first part of the solution that seems to work is to progamtically change the board at the top of the wpforo theme's index page first making sure I'm on a lesson page (becasue the standalone pages work ok).

First copy the wpforo/themes/2022/index.php to my child theme at /my-child-theme/wpforo/index.php

Then insert the followig code after 

if( ! defined( 'ABSPATH' ) ) exit;
if ( is_singular( 'lesson' ) ) {
  global$post;
  $lesson = new LLMS_Lesson( $post->ID );
  if ( PROGRAM_2_COURSE_ID === $lesson->get( 'parent_course' ) ) {
    WPF()->change_board(PROGRAM_2_BOARD_ID);
  }
}
Please note however that this does not update all elements on the page. For example the permalinks are correct but the page title is not.
Reply
Posts: 4
Topic starter
(@cloud9)
Active Member
Joined: 6 months ago

The only way I've been able to get everything to work when using multiple boards and shortcodes is to modify function wpforo_url() in wpforo/includes/functions.php and call WPF()->change_board(2) there.

Is there an action or filter in Wordpress or wpForo that will allow the change in board to be reflected in the call to wpforo_url?

 
Reply
Chris
Posts: 3519
Admin
(@chris)
Support Team
Joined: 2 years ago

Hi @cloud9,

About the shortcodes part, will try to fix that.

 

If you are using only one language in your Forum, I would recommend to Use Categories instead of board and Use wpForo Cross Posting addon to connect your Courses(Posts/Pages) with wpForo Topics.

WpForo Cross Posting addon has auto cross posting functionary. Which cross posts.

https://gvectors.com/product/wpforo-cross-posting/

Reply