Forums

Join
bbPress Support ForumsRequests and FeedbackRetrieving forum ID from post ID

Info

Tags

Retrieving forum ID from post ID

  1. 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?

  2. 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.

  3. Sweet, works perfectly, thanks.

  4. 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.

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

  6. Please see my table reference here for "forum"
    http://bbshowcase.org/reference/#bb_forums

  7. You must log in to post.