I simply need to display the "freshest" 3 topics from a specific forum in bbpress.
Is there a simple way to do this? Because I went nuts with trying to join tables. So here is my mysql solution (still cant code it well)....
So I instantly went into the database to check whats going on there, but I can't find a solution. sorting by post_modified didn't worked. So how can I get the FRESHEST topics under specific forum and display them?
Here is how the bbpress stores the data:
Forums -> Topics -> Reply on topics. Everything goes into wp_posts table.
Reply on Topics have a post_parent of Topics and Topics have post_parent of Forums. So definitely I cant use post_parent as a selection.
So I was thinking this (if someone can code this I would be grateful and even donate, because I am stuck somewhere).
Select all the posts from the table wp_posts that have post_type column which is 'reply'. Then check if the table wp_postmeta have a meta_value of 1263 (which is my parent forum) additionally it can be checked if meta_key from wp_postmeta is "_bbp_forum_id". This is how I will select all of the REPLYs.
After getting all of the replies under the FORUM I would like to check which 3 replies are freshest (getting the post_date value) and display their parent TOPICS. And I have to make sure that I dont have duplicates because the freshest 3 replies can be from the same TOPIC.
AM I COMPLICATING TOO MUCH ??? :)))
Any easier way?
THanks !!!
2 Answers
"I simply need to display the "freshest" 3 topics under a specific forum in bbpress."
It sounds like you're trying to take the long route to what the widgets described here already do:
If your needs differ from the widgets listed here please specify exactly why and we'll hopefully be able to narrow it down.
1Try this:
SELECT my_id, my_title, max(my_date) order_date FROM ( SELECT replace(post_title,'Antwort zu: ','') my_title, post_date my_date, if(strcmp(post_type,'topic'),post_parent,ID) my_id FROM wp_posts where post_type in ('topic', 'reply') and post_status = 'publish' ) my_temp_table group by my_id, my_title order by order_date desc limit 3 Replace 'Antwort zu: ' with a string depending on your forum language.