I solved it. Just change:
foreach( $poster_id as $index => $posterss_id ) {
global $post;
$post = get_post( $posterss_id->ID );
$linker_sluger = $link_sluger[$index]->guid;
/* ... */
}
Full Solution:
global $wpdb;
$poster_id = $wpdb ->get_results( "SELECT ID from wp_posts WHERE post_status="publish" AND post_type="post" AND post_content LIKE '%[gallery%' ORDER BY ID DESC" );
$link_sluger = $wpdb ->get_results("SELECT guid FROM wp_posts WHERE post_name LIKE 'albums%' ORDER BY guid DESC");
foreach( $poster_id as $index => $posterss_id ) {
global $post;
$post = get_post($posterss_id->ID);
$linker_sluger= $link_sluger[$index]->guid;
if( has_shortcode( $post->post_content, 'gallery' ) ){
echo'<div class="single-album home-last-gallery col-md-4 col-sm-12"> <a href="'.$linker_sluger.'">';
echo na_get_gallery_image_urls($posterss_id->ID, $linker_sluger);
echo '</a></div>';
}
}