Skip to:

Plugin aint working, what am I doing wrong

  • Hi,

    Welltried to make a plugin, but it aint working, why not?

    Plugin code:


    function get_portal_topics () {

    global $bbdb;

    return $bbdb->query("SELECT * FROM $bbdb->topics WHERE forum_id = 1 ORDER BY topic_time DESC LIMIT 0,10");



    This has to give a list I need, but turning it into my template it get this error:

    Warning: Invalid argument supplied for foreach() in /bbpress/bb-templates/portal-page.php on line 33

    Template code:

    <?php $portal_topics = get_portal_topics() ?>

    <?php foreach($portal_topics as $topic) :

    $portal_topic_posts = get_thread( $topic->topic_id); ?>

    <h1><a href="<?php topic_link(); ?>"><?php topic_title(); ?></a></h1>

    <?php printf(__('%1$s - <a href="%2$s">%3$s</a>'), get_topic_time(), get_user_profile_link($topic->topic_poster), get_topic_author()) ?><br/>

    <?php echo $portal_topic_posts[0]->post_text; ?>

    <div align="right"><?php printf(__('<a href="%1$s">Comments (%2$s)</a>'), get_topic_last_post_link(), get_topic_posts()) ?></div><br/>

    <?php endforeach; ?>

    Or my plugin is all wrong, or how I call it…. or both :)


Viewing 10 replies - 1 through 10 (of 10 total)

  • thomasklaiber


    maybe using $bbdb->get_results() instead of $bbdb->query()

    just an idea…

    changed some things it’s now:

    function get_portal_topics() {

    global $bbdb, $bb_table_prefix;

    return $bbdb->get_results("SELECT * FROM $bbdb->topics WHERE forum_id = 1 ORDER BY topic_time DESC LIMIT 0,10");


    Still same error when calling using:

    <?php $portal_topics = get_portal_topics(); ?>

    <?php foreach($portal_topics as $topic) :

    Etc etc


    Fatal error: Call to undefined function get_portal_topics()



    Ehm … I dont know what’s wrong, I put your code on my site … and it worked. Do all the other plugin-functions work?

    Hmm it was part of a larger plugin code, took the part out and put it in the plugins folder and it worked here aswell. Problem must be elswhere with the other plugin code.

    This results in a new question. My plugin has this code and works:


    // Get Portal topics

    function get_portal_topics() {

    global $bbdb;

    $pforum_id = 1;

    $number_of_topics = 10;

    return $bbdb->get_results("SELECT * FROM $bbdb->topics WHERE forum_id = $pforum_id ORDER BY topic_time DESC LIMIT 0,$number_of_topics");



    But I also want to pull the 1 and the 10 from the database $pforum_id = 1; and $number_of_topics = 10; are now manually done…

    How to do this then?




    You want to read out the two single vars from the db, am I right?

    So I suggest using $variable = $bbdb->get_var("SELECT...");.

    Already tried that (forgot to put it here too):

    $pforum_id = $bbdb->get_var("SELECT pforum_id FROM $bbdb->portal");

    But it doesn’t get the 1 out of the db. The query is good cause in phpMA it does return the 1. I get an error using this:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY topic_time DESC LIMIT 0,10' at line 1]

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

    As you can see, the 1 isn’t pulled/ used (WHERE forum_id = ?)



    your query doesn’t make sense. How can you be calling the result $pforum_id AND be using pforum_id in the query… also, how do you expect it to know what pforum_id is without the $ to tell it that it’s a variable?

    Eeuuhh hey I am a noob, why doesn’t it make sense? $pforum_id is the variable and pforum_id the field in the table bb_portal (they are named the same).

    The $pforum_id = 1 and is used in the last query. But the 1 can be different and is stored in de bb_portal table under pforum_id.

    So I want to pull that 1 first from the db (thought using ‘$pforum_id = $bbdb->get_var(“SELECT pforum_id FROM $bbdb->portal”);’ would work) and then use that result in the last query…

    Well that was the idea, but it aint working, how to fix it?

    Fixed it myself. It was the: FROM $bbdb->portal" that didn’t work. Changed it into FROM ".$bb_table_prefix."portal" and added $bb_table_prefix; in the global as well and all seems to work fine now.

    Working code:

    $pforum_id = $bbdb->get_var("SELECT pforum_id FROM ".$bb_table_prefix."portal");

    Thx for the suggestions given


Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.
Skip to toolbar