Skip to main contentSkip to footer

FileBird is one of many WordPress plugins that provide more control over the attachments in the Media Library. You can use the FileBird folders in Relevanssi searches to filter attachments based on their folder. Here’s a simple function you can add to your site:

add_filter( 'relevanssi_hits_filter', function( $hits ) {
    global $wpdb;
    if ( isset( $_REQUEST['folder'] ) ) {
        $folder = (int) $_REQUEST['folder'];
        $files  = $wpdb->get_col( "SELECT attachment_id FROM {$wpdb->prefix}fbv_attachment_folder WHERE folder_id = $folder" );

        $hits[0] = array_filter(
            $hits[0],
            function( $hit ) use ( $files ) {
                return in_array( $hit->ID, $files, true );
            }
        );
    }
    return $hits;
} );

Once you add this, you can use the folder parameter to restrict the search to a specific folder. The search ?s=search+term&folder=42 would only return attachments that are in folder 42. It’s possible to build more complex filtering, too; this should give you an idea of how the folder information can be used.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Co-authors Plus

…thanks to good design choices made by the Co-authors Plus developers. The plugin stores the extra authors in a custom taxonomy. Indexing custom taxonomies is elementary for Relevanssi. In order to make Relevanssi index all authors for posts, simply add “author” to the “Choose taxonomies to index” option and re-index….

Indexing embedded PDFs for the parent post

…this: add_filter( ‘relevanssi_excerpt_content’, ‘rlv_pdfjs_content’, 10, 2 ); This function will include the PDF content for excerpt-building. There’s a performance cost, so you have to try and see whether including the content slows down the search too much. One option is to read the PDF content to a custom field in…

PostX Pro
If you use PostX Pro to build a search results template using their Post Grid block, you’ll notice that the…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed