Skip to:
Content
Pages
Categories
Search
Top
Bottom

Retrieving forum ID from post ID


  • serpentguard1701
    Member

    @serpentguard1701

    I’m trying to improve on some breadcrumb code in the Edit Post section, and need to retrieve the forum ID from the post ID. Is this possible?

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

  • _ck_
    Participant

    @_ck_

    You can do it with a custom query.

    Something like

    $forum_id=$bbdb->get_var("SELECT forum_id FROM $bbdb->posts WHERE post_id=$post_id LIMIT 1");

    where $post_id is your post id.

    This will generate an extra query per page but for just editing that would be fine.


    serpentguard1701
    Member

    @serpentguard1701

    Sweet, works perfectly, thanks.


    _ck_
    Participant

    @_ck_

    It’s extremely easy to get forum <-> topic <-> post relationships in bbPress.

    Depending on where you are, you may just be able to do a

    global $topic,$bb_post;

    Then $topic or $bb_post will have the following objects inside:

    $bb_post

    post_id

    forum_id

    topic_id

    poster_id

    post_text

    post_time

    poster_ip

    post_status

    post_position

    $topic

    topic_id

    topic_title

    topic_slug

    topic_poster

    topic_poster_name

    topic_last_poster

    topic_last_poster_name

    topic_start_time

    topic_time

    forum_id

    topic_status

    topic_open

    topic_last_post_id

    topic_sticky

    topic_posts

    tag_count

    You use it like this:

    global $topic; echo "$topic->topic_title";

    or to answer your original question:

    global $bb_post; echo "$bb_post->forum_id";

    Of course doing it this way bypasses any filters that may be in place from plugins but that may not matter if you are just trying to do something simple.


    serpentguard1701
    Member

    @serpentguard1701

    what variables can you retrieve from the global $forum variable?


    _ck_
    Participant

    @_ck_

    Please see my table reference here for “forum”

    http://bbshowcase.org/reference/#bb_forums

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