Info
- 6 posts
- 2 voices
- Started 3 years ago by SerpentGuard1701
- Latest reply from _ck_
Retrieving forum ID from post ID
-
- Posted 3 years ago #
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?
-
- Posted 3 years ago #
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.
-
- Posted 3 years ago #
Sweet, works perfectly, thanks.
-
- Posted 3 years ago #
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_countYou 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.
-
- Posted 3 years ago #
what variables can you retrieve from the
global $forumvariable? -
- Posted 3 years ago #
Please see my table reference here for "forum"
http://bbshowcase.org/reference/#bb_forums -
You must log in to post.