Skip to:
Content
Pages
Categories
Search
Top
Bottom

Creating a New Query Object from within a Class


  • robsward
    Participant

    @robsward

    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 2 replies - 1 through 2 (of 2 total)

  • robsward
    Participant

    @robsward

    bump


    Robin W
    Moderator

    @robin-w

    suggest you look at how the forums widget lists the forums

    wp-content/plugins/bbpress/includes/common/widgets.php

    the forum widget starts at line 497

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