Don't know why, but doing this worked... In my search.php, no problem. In content-search.php, no result. while (have_posts()) : the_post(); $attachment = wp_get_attachment_url(get_the_ID()); set_query_var('document', $attachment); get_template_part('template-parts/content', 'search'); endwhile;