With the introduction of the new BB_Query_Class in bbPress 0.8.3, the old method of adding custom “views” to bbPress has been removed. You should no longer directly manipulate the
$bb_views
array, nor does the bb_views
hook work.
To add a view, you should instead use a new function: bb_register_view()
. Also available is bb_deregister_view()
for removing the default views or views added by other plugins.
function my_plugin_views() {
/*
bb_register_view(
$view_slug,
$view_title,
$bb_query_argument_array
);
*/
bb_register_view(
'more-than-5',
'Topics with more than five posts',
array( 'post_count' => '>5' )
);
bb_register_view(
'old-timers',
'Topics started before 2005',
array( 'started' => '<2005' )
);
// Remove default 'Topics with no tags' view
bb_deregister_view( 'untagged' );
}
add_action( 'bb_init', 'my_plugin_views' );
If you really need more complicated queries, you have the following filters at your disposal, just by registering your view in the above fashion (assuming the $view_slug
is “my-view”).
bb_view_my-view_distinct
bb_view_my-view_fields
bb_view_my-view_join
bb_view_my-view_where
bb_view_my-view_group_by
bb_view_my-view_having
bb_view_my-view_order_by
bb_view_my-view_limit
If that sounds complicated, it probably is 🙂 Most plugin developers will never have to do much besides filter a join or where here and there.