Skip to:
Content
Pages
Categories
Search
Top
Bottom

I want to get the parent forum name/ID of any topic


  • nayanboost
    Participant

    @nayanboost

    Could you please tell me how I can get the parent forum name/ID of current topic/any topic? I need code implementation. How to get so by code?

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

  • Robin W
    Moderator

    @robin-w

    bbp_get_topic_forum_id( $topic_id) ;


    nayanboost
    Participant

    @nayanboost

    Thank you. But how to get the current topic_id. I mean the topic I am viewing? bbp_get_topic_id() is returning 0.

    Please help


    Robin W
    Moderator

    @robin-w

    you’ll need to give me the context – ie what are you trying to do, and what code do you have so far


    nayanboost
    Participant

    @nayanboost

    Okay, here is what I am wanting to do.

    if (bbp_get_topic_forum_id(bbp_get_topic_id()) == ‘ID of the Parent forum’){
    do_something;
    }


    nayanboost
    Participant

    @nayanboost

    I am writing this code in functions.php and when I am trying to dump data using
    print_r (bbp_get_topic_id());

    It is returning 0.

    When the above mentioned condition is met I will redirect to another page.

    function test_rdr (){
        if (bbp_get_topic_forum_id(bbp_get_topic_id()) == ‘ID of the Parent forum’){
            wp_redirect('/test-page');
            exit;
        }
    }
    add_action('template_redirect', 'test_rdr')

    Please help me to get over with it.


    Robin W
    Moderator

    @robin-w

    ok, without getting heavily involved in coding a solution for you (which is my paid day job 🙂 ) I guess that you have hooked to ‘template redirect’ which fires on everypage, so when WordPress displays the test-page it looks again for a value of topic_id, which on the test page does not exist, so returns zero.

    if your code is working in that it redirects to test page, then you could try appending the topic id and picking that up in $_REQUEST

    eg (untested)

    wp_redirect('/test-page/?topic_id='.bbp_get_topic_id());

    and then on test page use the code

    if (isset($_REQUEST['topic_id'])) $topic_id = $_REQUEST('topic_id') ;

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