Skip to:
Content
Pages
Categories
Search
Top
Bottom

Creating a New Query Object from within a Class

  • @robsward

    Participant

    Hi,

    I’m trying to retrieve a simple list of all forums on a site, for which I need to have a loop. I’m trying to create one from within a class in my plugin using this function:

    public function forum_list(){
    
    	$forums		= array();
    
    	if ( bbp_has_forums() {
    		while ( bbp_forums() ) {
    
    			bbp_the_forum();
    
    			$forum_id = bbp_get_forum_id();
    			$forum_name = bbp_get_forum_title();
    			$data = array( 'ID' => $forum_id, 'name' => $forum_name );
    
    			$forums[] = $data;
    
    		//} // while()
    	} // if()
    
    	return $forums;
    
    } // get_forum_list()

    Which is called inside the construcor like so:

    $this->forums = $this->forum_list();

    This is telling me there is no object (Call to a member function get() on a non-object). The function works perfectly well outside the class, but inside it fails. What am I missing?

Viewing 3 replies - 1 through 3 (of 3 total)
  • @robsward

    Participant

    There are a couple of issues with that code up there. Correct function is this one:

    public function forum_list(){
    
    	$forums		= array();
    
    	if ( bbp_has_forums() ) {
    		while ( bbp_forums() ) {
    
    			bbp_the_forum();
    
    			$forum_id = bbp_get_forum_id();
    			$forum_name = bbp_get_forum_title();
    			$data = array( 'ID' => $forum_id, 'name' => $forum_name );
    
    			$forums[] = $data;
    
    		} // while()
    	} // if()
    
    	return $forums;
    
    } // get_forum_list()

    @karjaw

    Participant

    i’m sorry robs, i can’t help you coz i’m newbie, maybe other poeple 🙂

    @robsward

    Participant

    Thanks for trying karjaw!

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