$post->ID, 'post_type' => 'parrain' ); $myquery = new WP_Query( $args ); $i = 0; $posts = $myquery->get_posts(); foreach ($posts as $post) { $custom = get_post_custom($post->ID); $year = $custom['year'][0]; $output[$year][] = $post; } krsort($output); $j = 0; $posts = array(); foreach ($output as $k => $year) { foreach ($year as $v) { //echo $k; $posts[$j] = $v; $j++; } } foreach ($posts as $post) { $custom = get_post_custom(); //var_dump($previousYear); if (!isset($previousYear) || $previousYear != $custom['year'][0]) { // echo '

'.$custom['year'][0].'

'; $previousYear = $custom['year'][0]; } get_template_part('content_post_thumb'); } wp_reset_postdata(); ?>