Skip to:
Content
Pages
Categories
Search
Top
Bottom

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

  • @_ck_

    Participant

    I’m not sure if this has been addressed elsewhere already or a plugin already exists but for novices that have even just a beginner’s knowledge of how php+mysql works I want to show you how easy it is to show bbPress info inside of WordPress and vise-versa.

    You should NOT be using overly complex plugins like bbPress-Live or parsing RSS feeds if you have WordPress and bbPress sharing the same database but different tables. Instead, it’s a piece-of-cake to grab info from each other directly and display it. You don’t even need a plugin, you can code it right into your templates (as long as you know they will remain working together).

    So I’ll give some examples here and then if anyone has questions feel free to ask.

Viewing 25 replies - 26 through 50 (of 60 total)
  • @ganzua

    Member

    Ipstenu; I’m not requesting at all :) just suggesting in case CK has another inspired day and has an unrestrained need of writing another guide. Just that, no demand.

    @_ck_

    Participant

    Once 1.0 beta is released things will be far more solid.

    You have to understand that 1.0 is almost a 75% re-write (or re-structuring) of 0.9 so many things have changed. To an end user it seems the same but that’s because of much backwards compatibility work by Sam.

    bbPress 1.0 is 150% the code size of 0.9

    So when 1.0 goes beta, that would be a good time to start documentation.

    @_ck_

    Participant

    One final addition to this that I didn’t think of mentioning earlier.

    To use bbPress queries like these on a foreign (non-bbPress / non-WordPress) PHP page, all you need to do is include the bbPress core like this at the start:

    <?php require('/local-path-to-bbpress/bb-load.php'); ?>

    or to load WordPress core use this

    <?php require('/local-path-to-wordpress/wp-config.php'); ?>

    (change the ‘local-path’ bit to your local path)

    and remember to use $wpdb on WordPress pages, vs $bbdb on bbPress pages.

    @ganzua

    Member

    and remember to use $wpdb on WordPress pages, vs $bbdb on bbPress pages

    I want to query $bbdb from a wp page. In particular, I want to fetch the total amount of views from your bb Topic Views plugin. This code didn’t work;

    <?php
    global $bbdb;
    $results=$bbdb->get_results("SELECT SUM(meta_value) FROM bb_meta WHERE object_type='bb_topic' AND meta_key='views'");
    $results=$bbdb->get_results($query);
    ?>

    WordPress is installed in /wordpress/ and bbpress in /wordpress/bbpress/ both deep integrated. What’s missing?

    @_ck_

    Participant

    I need more info than “didn’t work”

    Try replacing $bbdb with $wpdb

    @ganzua

    Member

    I need more info than “didn’t work”

    Fatal error: Call to a member function get_results() on a non-object in wordpress/wp-content/themes/mytheme/header.php on line 149 (line where I placed the code)

    Try replacing $bbdb with $wpdb

    no error but what I want is to query bbpress data base. Whenever I echo $results there is no answer.

    @_ck_

    Participant

    That is with bbPress 1.0 right? the object_type is for 1.0

    You get nothing using get_results because it returns an array – use get_var instead

    <?php
    global $bbdb;
    $result=$bbdb->get_var("SELECT SUM(meta_value) FROM bb_meta WHERE object_type='bb_topic' AND meta_key='views'");
    echo $result;
    ?>

    @ganzua

    Member

    That is with bbPress 1.0 right? the object_type is for 1.0

    Yes, it is bb 1.06a with wp 2.7 :)

    I tried with get_var and I get the same error for get_var;

    Fatal error: Call to a member function get_var() on a non-object in….

    but then I changed $bbdb for $wpdb and it works. Why? I don’t understand this.

    @_ck_

    Participant

    Because for some reason the bbdb object must not be created when deeply integrated under 1.0

    Must have something to do with backpress which re-uses wp functions.

    @ganzua

    Member

    Ok, thanks for your help :) I’m going to try more of these queries. I find them very useful to integrate small details.

    @ganzua

    Member

    This other nice trick by you doesn’t work either from the wp comments template;

    global $wpdb;
    $result=$wpdb->get_var("SELECT COUNT(*) FROM bb_posts WHERE poster_id = $user_id AND post_status = 0");
    echo $result;

    No errors though. I tried replacing poster_id with wp comment_author_id but it didn’t make it.

    What I was trying to do is to put the the whole count of wp comments and bbpress posts all together.

    The previous question was because I produced a hit counter that runs for both; wp and bbpress. I added the total hits of the bbpress post views plugin to the wp counterize plugin. It works but I think I did this by the hard way.

    @edlvg

    Member

    Hello, so how’s the code if we’d like to add posteb by… in …

    I get the topic and forums list but’d like to show the author.

    Tried the codes at the beginning but doesnt seem to work, fatal errors :S

    thanks in advance

    ernesto

    @_ck_

    Participant

    edlvg you want something like

    echo "Posted by $result->topic_poster_name";

    I just realized I completely missed explaining how to get forum names via WordPress, I was telling people to use bbPress functions which is of course impossible from WordPress. Let me know if anyone still needs the help.

    @swaymedia

    Member

    can you please just do a step by step tutorial, it is really hard to follow and i dont know which piece of code goes where.

    @edlvg

    Member

    thanks _ck_ worked beautiful, sounds quite helpful having a tutorial though, :p

    @atsutane

    Member

    Well since bbpress and wordpress are using ezsql… you can find ezsql tutorial here.

    http://justinvincent.com/docs/ezsql/ez_sql_help.htm

    @filiped

    Member

    Hey guys! I can’t make $result->topic_poster_name work in my 0.9.0.4 instalation.

    Is this the right function for this version?

    // REPLIES

    $query_replies="SELECT * FROM bb_posts WHERE topic_id=$topic_id AND post_id != $first_reply_id AND post_status=0 ORDER BY post_time DESC";

    $results_replies=$wpdb->get_results($query_replies);

    $replies_text = "";

    foreach ($results_replies as $result) {

    echo $result->post_text;

    echo $result->topic_poster_name;

    }

    The post_text works perfectly, but the poster_name returns me nothing. Any idea?

    @filiped

    Member

    Done!

    get_post_author($result->post_id);

    Could find in:

    http://phpxref.ftwr.co.uk/bbpress/nav.html?_functions/index.html

    @_ck_

    Participant

    Yes but that wouldn’t work from the WordPress side.

    The correct way to do it directly would be to either use the topic table which has the topic_poster_name (not bb_posts) or to use a LEFT JOIN on the user table to fetch the user_login.

    The LEFT JOIN will also get you the display name.

    But there are several problems with your question.

    First of all, you mean Display Name, not Nice Name, unless you are trying to use it in a way I don’t understand.

    Secondly 0.9 doesn’t use Display Name.

    Third,

    “SELECT * FROM bb_posts WHERE topic_id=$topic_id AND post_id != $first_reply_id AND post_status=0 ORDER BY post_time DESC”

    is a very inefficient query, there’s no LIMIT, you are using *

    what exactly are you trying to find?

    @migran

    Member

    dear _ck_,

    i did as you suggested with adding

    <?php require(‘/local-path-to-bbpress/bb-load.php’); ?>

    to wordpress but it conflicts with wp-admin.

    any idea how to resolve this?

    https://bbpress.org/forums/topic/wordpress-integration-login#post-55751

    Tomwi: can you post your code for showing mentioned template

    *post title*

    Posted by: *user* in *forum*.

    or send it to me – procka@tasty.sk

    greets

    Vlado

    @ashfame

    Participant

    How does using $wpdb & $bbdb differs from using $results=mysql_query($query);?

    @kawauso

    Member

    $wpdb and $bbdb have nice sanitizing functions and caching of results if I remember correctly

    https://codex.wordpress.org/Function_Reference/wpdb_Class

    They can also be used to retrieve table names for the respective package

    @ashfame

    Participant

    Thanks ! I forgot that I should check out the codex for that.

    @ashfame

    Participant

    @Kawauso

    I think using $wpdb & $bbdb should sanitize by them self but reading the page on codex it looks like that we need to do that explicitly. I am a lil confused. Can you please clarify?

Viewing 25 replies - 26 through 50 (of 60 total)
  • You must be logged in to reply to this topic.
Skip to toolbar