Skip to main content
added 168 characters in body
Source Link
Morgan
  • 137
  • 10

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;

EDIT

As mention @Dave Romsey, do

add_action( 'pre_get_posts', 'attachment_search' );

instead of

add_filter( 'pre_get_posts', 'attachment_search' );

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;

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;

EDIT

As mention @Dave Romsey, do

add_action( 'pre_get_posts', 'attachment_search' );

instead of

add_filter( 'pre_get_posts', 'attachment_search' );
Source Link
Morgan
  • 137
  • 10

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;