I managed to get it work by creating one code snippet:
function render_album_list_item($album) {
$output="<div><figure>" . get_the_title($album) . ' </figure></div>';
return $output;
}
function display_albums_shortcode() {
$query = new WP_Query(
array(
'post_type' => 'albums'
));
$output="<section>";
if ($query->have_posts()):
while ( $query->have_posts() ):
$album = $query->the_post();
$output .= render_album_list_item($album);
endwhile;
endif;
$output .= '</section>';
wp_reset_postdata();
return $output;
}
add_shortcode('display_albums', 'display_albums_shortcode');
Still, is this the best way to achieve this goal?