ACF pro: Group teaser by datepicker year and display custom sub fields [closed]

The reason you can’t use ACF or functions such as the_title() is because they can only be accessed from inside The Loop (see here https://codex.wordpress.org/The_Loop).

Its unnecessary to have multiple loops so I’ve merged them into one which will display any post data you need. Within this loop it checks whether the current post’s year is equal to the previous post’s year before it displays it.

<?php /* Template Name: Konzerte */
// Überschrift-Element mit Headline, Bild, Schwung und Text; 800px hoch
require('inc/stage.php');

    global $post;

    // get posts
  $posts = get_posts(array(
      'post_type'         => array('concertreport', 'concertannouncement'),
      'posts_per_page'    => -1,
      'meta_key'          => 'concertdate',
      'orderby'           => 'meta_value',
      'order'             => 'DESC'
  ));

  $group_posts = array();

    if ($posts) {
      $previous_year="";
      foreach ($posts as $post) {
        $date = get_field('concertdate', $post->ID, false);
        $date = new DateTime($date);
        $current_year = $date->format('Y');

        // If $previous_year is empty, display $current_year
        if ($previous_year == '') {
            echo '<h2>' . $current_year . '</h2>';
        }
        // Else if $previous_year is not equal to $current_year, display $current_year
        else if ($previous_year !== $current_year) {
            echo '<h2>' . $current_year . '</h2>';
        }

        $previous_year = $date->format('Y');
        echo $date->format('d-m-Y');
        echo "https://wordpress.stackexchange.com/";
        echo get_the_title();
        echo '<br>';
      }
    }
?>

<?php get_footer(); ?>

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)