Show posts by quarter

Let’s define a helper function to map a month to a quarter:

function wpse_get_month2quarter( $month )
{
    return ceil( $month / 3 );
}

We could then consider what to do with input values that are not integers in the set {1, ..., 12}.

ps: I got the idea for the formula from this Excel blog by Gašper Kamenšek

To get the Quarter within the loop we can e.g. use:

echo wpse_get_month2quarter( get_the_date( 'n' ) );

Example

Here’s one idea for your loop:

if ( $custom_posts->have_posts() ) : 

    $prev = null;

    while ( $custom_posts->have_posts() ) : 

        $custom_posts->the_post();

        $current = sprintf( 
            '%d Q%d', 
            get_the_date( 'Y' ), 
            wpse_get_month2quarter( get_the_date( 'n' ) )
        );

        if( $prev !== $current )
        {
            printf( '<tr><td colspan="3">%s</td></tr>', $current );
            $prev = $current;
        }

        // ... etc ...

where we inject each quarter section once and assume that query is ordered by date.

But there are many ways to implement this.

If possible you should try to use and modify the main query, via pre_get_posts, instead of introducing another secondary query.