Support » Plugin: Search Everything » [Plugin: Search Everything] Filtering the attachments by mime type

  • I am using the function to search attachments and would like to filter out images from attachments listed in the search results, or alternatively to just search for PDF attachments.

    The site I’m working on has a lot of uploaded PDFs and it’d be useful to get them to show up in the search results (which works fine with Search Everything), but it also lists all images uploaded, which are not so relevant to the site search.

    Would be great if someone knew if this was possible and how to do it.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Couldn’t figure out a plugin-related and neat way of doing this, but ended up filtering the search results in the loop with something like this:

    if ( get_post_type() == 'attachment' ) {
      if ( get_post_mime_type() == 'application/pdf' ) {

    which works OK for now.

    Karl, thanks a lot for posting this. Unfortunately I have not got the code statement you posted to work in my loop file. When I do a direct copy of your code and inputted it into my loop file – no matter where I put it I get a syntax error. I have copied some of my code below and was wondering if you could give me any recommendations?

    Also, what if I wanted to concatenate Word and Excel files to appear?

    <?php /* LOOP TO DISPLAY POSTS */ ?>


    global $wp_query;

    $args = array(‘post_type’ => array(‘post’, ‘departments’, ‘featuredemp’));

    $args = array_merge( $args, array_filter( $wp_query->query_vars ) );

    query_posts($args); ?>

    <?php // NO POSTS TO DISPLAY? ?>

    <?php if ( ! have_posts() ) : ?>

    <p class=”intro”><?php echo __(‘Apologies, but no results were found for the requested archive.
    Perhaps searching will help find a related post.’,’duotive’); ?>

    <?php endif; ?>

    <?php // HAVE POSTS TO DISPLAY? ?>

    <?php while ( have_posts() ) : the_post(); ?>

    <div class=”post blog-classic”>


    ” title=”<?php echo __(‘Permalink to ‘, ‘duotive’).the_title_attribute( ‘echo=0’ ); ?>” rel=”bookmark”>

    <?php the_title(); ?>


    <?php if ( has_post_thumbnail() ): ?>

    <?php $thumbnail_src = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) ); ?>

    ” title=”<?php the_title();?>”>

    <img src=”<?php echo get_bloginfo(‘template_directory’);?>/includes/timthumb.php?src=<?php echo $thumbnail_src; ?>&h=180&w=640&zc=1&q=100″ alt=”<?php the_title(); ?>” />

    <?php endif; ?>

    <?php if(is_search()): ?>

    <?php the_excerpt(); ?>

    <?php else: ?>

    <?php the_content(”); ?>

    ” title=”<?php the_title();?>”><?php echo __(‘Read More »’,’duotive’); ?>

    <?php endif; ?>

    <div class=”post-meta”>

    <span class=”post-date”><?php echo __(‘posted on ‘,’duotive’); ?><?php the_time(‘F’); echo ‘ ‘; the_time(‘jS’); echo ‘ ‘; the_time(‘Y’);?></span>

    <?php if ( count( get_the_category() ) ) : ?>

    <span class=”categories-link”>, <?php echo __(‘Categories:’,’duotive’).’ <span class=”title”>’.get_the_category_list( ‘, ‘ ).'</span>’; ?></span>

    <?php endif; ?>

    <?php $tags_list = get_the_tag_list( ”, ‘, ‘ ); ?>

    <?php if ( $tags_list ): ?>

    <span class=”tag-links”>

    <?php echo __(‘Tags:’,’duotive’).’ <span class=”title”>’.$tags_list.'</span>’; ?>


    <?php endif; ?>

    <!– end of post meta –>


    <!–end of blog-classic –>


    <?php endwhile;?>

    <?php if(function_exists(‘wp_pagenavi’)): ?>

    <div id=”navigation”>

    <?php wp_pagenavi();?>


    <?php endif; ?>

    Hi dojwebmaster,

    You should be able to put it right after the loop starts, which is right after:

    <?php while ( have_posts() ) : the_post(); ?>

    Then place:

    if ( get_post_type() == 'attachment' ) {
      if ( get_post_mime_type() == 'application/pdf' ) {

    which essentially says, “if an attachment, then..”, and then goes
    through all attachments and says, “if a pdf file..”. Could it be that the syntax error you receive is because you don’t close these two IFs? At the end of the loop you’re checking, before the:

    <?php endwhile; ?>

    you need to close them:

    <?php }
    } ?>

    Hopefully that helps.

    Mucho gracias amigo, looks like I did get it to work… I think? Now with this new construct in the code, will it ONLY return PDF’s in the search?

    It appears that what it did for me, meaning that I was only getting PDF’s to come back in my search’s but not Post or Page data?

    My goal is to have Post, Page and File Attachments but to omit JPG and other image formats.

    Then you could probably do something like this:

    if ( get_post_type() == 'attachment' ) {
      if ( get_post_mime_type() == !'image/jpeg' && !'image/png' && !'image/gif' ) {
    } else {

    The above should (I hope!) first check if an attachment, then check that it’s NOT Jpeg, Gif or PNG, then print whatever data you want to output. If not an attachment, you can print data for anything else.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Search Everything] Filtering the attachments by mime type’ is closed to new replies.