Forums Forums Search & Filter Pro Want search to include all attachments Except Images

Viewing 10 posts - 1 through 10 (of 28 total)
  • Anonymous
    #82886

    How do I exclude images from the search results. We still want pdfs, audio files, and video (etc) to show in results but no images. How do I do this?

    Anonymous
    #82888
    This reply has been marked as private.
    Trevor
    #83096

    The only way I can think of doing this without some coding is to add a custom field to attachments to specify the type and use this to exclude images.

    Anonymous
    #83248

    Any way to do this with post-mime-types? Attachments are assigned different types… I’m just not familiar with the coding to exclude a certain mime type.

    Trevor
    #83316

    Hi. Ross (the developer) has reminded me that the mime type is already saved as a custom field against the attachment post, and we have the “post meta” tab in our search forms to exclude things like this.

    Anonymous
    #89022

    Awesome! Could you tell me how to do this? I’m not sure what option to select and what to put in to EXCLUDE just the images and keep the rest of the types. Any idea of what I code I need to insert in order to exclude images? Using the Post Meta section is pretty confusing. Our client is really set on having images be excluded from the results and is looking for a solution asap.

    Trevor
    #89084

    OK, I will need to go digging. My guess is that in the Post Meta rules you add a rule to filter on the _wp_attachment_metadata key. In your form, do you have the Media post type checked for your search (as that is containing the files you want to search)?

    Anonymous
    #89459

    Yes, we have media checked in the form as well as posts and pages. We just want to exclude images from coming up but allow other media types (specifically PDFs) to show up in the results.

    Trevor
    #89698

    Hi

    I think I was going down the wrong track. what you need to do is use our Edit Query argument filter.

    Or edit the query arguments directly. It rather depends how your search is setup. What Display Results method are you using?

    For mine, and your, reference as we progress this support request, we will use the logic of this code snippet to modify the wp query:

    $unsupported_mimes  = array( 'image/jpeg', 'image/gif', 'image/png', 'image/bmp', 'image/tiff', 'image/x-icon' );
    $all_mimes          = get_allowed_mime_types();
    $accepted_mimes     = array_diff( $all_mimes, $unsupported_mimes );
    $attachment_query   = new WP_Query( array(
        'post_type'         => 'attachment',
        'post_status'       => 'inherit',
        'post_mime_type'    => $accepted_mimes,
        'posts_per_page'    => 20,
    ) );

    We will not use this exactly as above, but the method.

    Anonymous
    #89818

    We’re using “As an Archive” as the method.

    Use a custom template for results – Is checked

    Filename for custom template: searchBlog.php (basically just copied other search results page template but modified for looks)

    Make searches bookmarkable – checked

    Only use Ajax on the results page – checked

    Scroll window to: none on all

    Results container – #search-results

    Pagination selector – .pagination a

    Let me know if you need other settings or if you need access to our backend or files. We really need to get this solved ASAP. Thanks!

Viewing 10 posts - 1 through 10 (of 28 total)