Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Here’s how to show bbPress info inside WordPress without full integration


_ck_
Participant

@_ck_

Now we need to put together a correct mysql query.

Let’s try something simple.

SELECT * FROM bb_topics WHERE topic_status=0 ORDER BY topic_time DESC LIMIT 10

SELECT means “grab the following”

the asterisk means “all the fields in the table”

FROM bb_topics is kinda obvious, it’s the table we want

topic_status=0 means it’s topics not deleted

ORDER BY topic_time DESC means put the newest topics on top

LIMIT 10 means we want only the first 10

Let’s say we also wanted to exclude topics that were closed, since people can’t reply, we don’t want to tease them. In that case you would change the

WHERE topic_status=0

to

WHERE topic_status=0 AND topic_open=1

or let’s say you only wanted “stickies”

WHERE topic_status=0 AND topic_sticky!=0

Okay now to use that in WordPress we do the following:

global $wpdb;
$query="SELECT * FROM bb_topics WHERE topic_status=0 ORDER BY topic_time DESC LIMIT 10";
$results=$wpdb->get_results($query);

If all goes well, WordPress will then execute the query and then fill $results with the answers.

Now comes the output part.

Skip to toolbar