Skip to:

Problem with bbp_is_forum_category function

  • codenameita


    Hi there,
    I’m trying to write some advanced search functions for BBpress. One of these should let people search only in the forum or subforum they currenty are in. I followed several examples posted on the net and tried to refine them myself.
    Unfortunately, I am experiencing a problem with the bbp_forum_get_subforums fuction.
    The fuction I am writing should be able to get the list of subforums present in a category type forum when the search is fired from a category type forum.
    The code is as follows:

    //If the forum is a category, then search in all the subforums
     if( bbp_is_forum_category($forum_id)){
            $sub_forums = bbp_forum_get_subforums($forum_id);
            $subforum_id = array_column($sub_forums,'ID');
    	$min_subforums = min($subforum_id);
    	$max_subforums = max($subforum_id);
    	$r['meta_query'] = array(
       	        'key' => '_bbp_forum_id',
           		'value' => array($min_subforums,$max_subforums),
    	   	'compare' => 'BETWEEN',

    Unfortunately, bbp_forum_get_subforums($forum_id) gives a false result.
    Strangely enough, if I try to put the same code in a fuction and add it with “add_action” to a forum page, it gives me the corret list of subforums if the current forum is a category.
    Can someone please help me addressing this problem? I am using the latest version of WP and BBpress.

Viewing 2 replies - 1 through 2 (of 2 total)

  • codenameita


    I have solved the problem.
    This line of code resets the post_parent entry of the array args to the current forum id.
    $r['post_parent'] = bbp_get_forum_id( $r['post_parent'] );
    Creating a new function with that line commented solved the problem.

    Robin W


    great – glad you are fixed

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar