LPH
Well-known member
I'm trying to replace older code that does not use $fetchOptions and $conditions.
Here is the old code.
	
	
	
		
Here is the New code
	
	
	
		
Unfortunately the WHERE for parent_node_id isn't being honored. I looked in the model and don't see a way to set a condition to only return forums from a certain category (parent_node_id).
Does anyone know the correct condition or fetchOption to get the forums for a particular category?
				
			Here is the old code.
		PHP:
	
	/** @var $node_qry XenWordXFForums */
$node_qry = "
            SELECT node_id, title, display_in_list, node_type_id, parent_node_id FROM `xf_node`
            WHERE display_in_list = 1 AND node_type_id = 'Forum' AND parent_node_id = '$cat_id'
            ORDER BY `title` ASC
            LIMIT $number_of_forums
         ";
$nodes = XenForo_Application::get( 'db' )->fetchAll( $node_qry );
	Here is the New code
		PHP:
	
	// Temporarily Assign as working through code
$instance['show_categories'] = 1;
$instance['show_number_of_forums']= 3;
//  End Temporary Settings
$cat_id = $instance['show_categories']; // parent_node_id
$number_of_forums = $instance['show_number_of_forums']; // limit
$conditions = array(
  'display_in_list' => 1,
  'parent_node_id' => $cat_id
);
$fetchOptions = array(
  'join' => XenForo_Model_Thread::FETCH_USER
          | XenForo_Model_Thread::FETCH_FORUM
          | XenForo_Model_Thread::FETCH_FIRSTPOST,
  'limit' => $number_of_forums,
  'order' => 'display_oder',
  'orderDirection' => 'desc'
);
/** @var  $forumModel XenForo_Model_Forum */
$forumModel = XenForo_Model_Forum::create('XenForo_Model_Forum');
$nodes = $forumModel->getForums( $conditions, $fetchOptions );
$visitor = XenForo_Visitor::getInstance();
foreach ( $nodes AS $node ) {
  $visitor->setNodePermissions( $node['node_id'], isset( $node['node_permission_cache'] ) );
  if ( $forumModel->canViewForum( $node ) ) {
    echo(
      "<div class='entry-meta'><a href='"
      . XenForo_Link::buildPublicLink( 'canonical:forums', $node )
      . "'>"
      . XenForo_Helper_String::wholeWordTrim( $node['title'], 40 )
      . "</a><br />"
    );
  }
}
	Unfortunately the WHERE for parent_node_id isn't being honored. I looked in the model and don't see a way to set a condition to only return forums from a certain category (parent_node_id).
Does anyone know the correct condition or fetchOption to get the forums for a particular category?