Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: bb_register_view – from SQL to array


_ck_
Participant

@_ck_

I’ve never figured out how to do direct query setup for views, so what I do is just short-circuit the internal function and write my own. For example:

bb_register_view("highest-rated","Topics with the highest rating",array('append_meta'=>false,'sticky'=>false));
add_action( 'bb_custom_view', 'highest_rated' );

function highest_rated( $view ) {
if ($view=='highest-rated') {
global $bbdb, $topics, $view_count, $page;
$limit = bb_get_option('page_topics');
$offset = ($page-1)*$limit;
$where = apply_filters('get_latest_topics_where',"WHERE topic_status=0 ");
$query = " FROM $bbdb->topics $where ";
$restrict = " ORDER BY cast(topic_posts as UNSIGNED) DESC LIMIT $limit OFFSET $offset";

$view_count = $bbdb->get_var("SELECT count(*) ".$query);
$topics = $bbdb->get_results("SELECT * ".$query.$restrict);
$topics = bb_append_meta( $topics, 'topic' );
}
}

.

Obviously change the query to your own and that might work for you. Don’t forget to use $bbdb->bb_ratings the $bbdb part is critical.

Skip to toolbar