I try to display a list of custom posts grouped by categories using a solution from here (the 1st option/example). I adapted the code only a little to my needs, but it freezes (get a white display if it isn't commented) my installation/blog, because of this line (as it seems to me): $term_ids = array_map(function($t) { return $t->term_id, }, $terms);
. I found that by commenting parts of the code. What is wrong with it?
My full code:
function yesterday_events2() {
$terms = get_terms( 'event-categories' );
$term_ids = array_map( function( $t ) { return $t->term_id }, $terms );
$posts = get_posts(
array(
'nopaging' => true,
'tax_query' => array(
array(
'taxonomy' => 'event-categories',
'field' => 'id',
'terms' => $term_ids,
) ),
) );
foreach( $terms as $t ) {
$posts_in_term = array_filter( $posts, function( $p ) use ( $t ) {
// has_term likely triggers a DB hit...
return has_term( $t->term_id, 'event-categories', $p );
} );
// do stuff with $posts_in_term
}
}