How to display list of custom post taxonomy terms and their posts (if any)?

As per the docs: https://developer.wordpress.org/reference/functions/get_terms/ the way to get terms has changed in WP 4.5. It’s always good to keep the new way of dev.

Thats said, this code seems to work on my side:

    $taxonomy       = 'city';
    $args           = array(
        'taxonomy' => $taxonomy,
        'orderby'  => 'count',
        'order'    => 'DESC',
    );
    $taxonomy_terms = get_terms( $args );

    if ( $taxonomy_terms ) {
        foreach ( $taxonomy_terms as $taxonomy_term ) {

            $args = array(
                'post_type'      => 'location',
                'posts_per_page' => - 1,
                'hide_empty'     => false,
                'tax_query'      => array(
                    'relation' => 'AND',
                    'taxonomy' => $taxonomy,
                    'terms'    => $taxonomy_term->slug,
                    'field'    => 'slug',

                ),
            );

I usually use https://generatewp.com/wp_query/ to generate my queries.

error code: 523