> I have a content type representing a magazine issue, that are returned
> through a custom rewrite rule. It saves the year of publication in the
> postinfo table. When displaying the posts, I want to display them in
> year order and grouped by years. Is this possible using Posts::get() ?
> If not, does anyone have any recommendations on how to do it ?
This sorts by postinfo field and handles pagination. Refactor my code :)
public function filter_theme_act_display_imprints( $handled, $theme )
{
$paramarray['fallback']= array(
'{$type}.multiple',
'multiple',
);
// Makes sure the imprint page displays only imprint
$paramarray['user_filters']= array(
'content_type' => Post::type('imprint'),
);
$theme->imprint_page = Post::get( array( 'slug' => 'imprint',
'content_type' => Post::type( 'page' ) ) );
$page = $theme->matched_rule->named_arg_values['page'];
$limit = 5;
$offset = 0;
// Calculate the OFFSET based on the page number
if ( isset( $page ) && is_numeric( $page ) ) {
$offset = ( intval( $page ) - 1 ) * intval( $limit );
}
$params = array(Post::type('imprint'));
$query = <<<SQL
SELECT *
FROM habari__posts as posts
LEFT JOIN habari__postinfo as postinfo
ON
posts.id = postinfo.post_id
WHERE posts.content_type = ?
AND
postinfo.name = 'year'
ORDER BY postinfo.value DESC
LIMIT $limit
OFFSET $offset
SQL;
$results = DB::get_results( $query, $params, 'Post' );
$theme->imprint_posts = $results;
$theme->act_display( $paramarray );
return TRUE;