1. Document Library Pro
  2. Document Library Options

Searching the document library

Document Library Pro has a range of flexible search options which make it easy for people to find documents using a particular search term. Use it alone or with filters, in which people can refine the list of documents by selecting from a set of pre-defined filter options.

The plugin provides two types of document search:

Search box above the document library

By default, Document Library Pro displays tables with a search box above the table or grid (top-right). This allows people to instantly filter the table to items with a specific keyword or search term.

In this example, the user has typed the term "policy" into the search box. This has filtered the table to the 2 items which match that term:

Document Library Pro Search Term Option

Document Library Pro also has options to change the position of the search box or hide it altogether.

Document Library Pro standalone search box

As well as being able to display a search box above the document library, you can use a widget or shortcode to add a 'Document search' box anywhere on your site (e.g. the homepage). This allows people to enter a search term before viewing the document library.

The styling of the document search is inherited from the default search box which comes from WordPress and your theme. You can change the styling using custom CSS.

Widget

If your theme has a sidebar area then you can add the document search widget to it:

  1. Go to Appearance → Widgets (or the Customizer if you prefer to edit widgets there).
  2. Add the 'Document Library Pro: Search Box' widget to one of your sidebars.
  3. Add any or all of the following information:
    1. Title - The title to be displayed above the widget, e.g. "Search the Document Library".
    2. Placeholder - The watermark text which will appear inside the search field, e.g. "Search resources".
    3. Button Text - If required, then you can change the text which appears on the button.

Shortcode

The following shortcode will add a document search anywhere on your site:

[doc_search]

You can customize the shortcode using the placeholder and button_text parameters, for example: [doc_search placeholder="Search resources" button_text="Search Now"]

Search results page

Document Library Pro creates a page for displaying the search results. You can find this in the list of 'Pages' in the WordPress admin.

The document search results page uses the default template from your theme. This means that if your theme's default template has a sidebar then the same sidebar will appear on the document search results, otherwise it will be full-width.

The slug of this page is 'document-search' by default. If you like, then you can change the permalink/slug of this page to anything you like, e.g. 'resource-search'.

Search logic

If you are using the table layout without lazy load or folders enabled, then  the search box will search all data in the library, so users can search by category, tag, date, etc.

If you are using the grid layout, or the table layout with lazy load or folders enabled, then the search works differently. Instead of searching the contents of the table, the search box looks in the document title, excerpt and the full content of the document (regardless of whether these fields are actually visible in the document library). This is because with these options, Document Library Pro hasn't yet loaded all the documents - and therefore it can't search the contents of the current page. Instead, it has to use WordPress' built-in indexing function, which indexes some types of field but not others. 

If you want to search by other fields then we recommend one of the following workarounds:

  • Add the extra data to the title, excerpt or content fields so that it will be searchable in lazy load, grid mode and folder view.
  • If you're using a lazy loaded table and want people to be able to find documents by category, tag or custom taxonomy, then you can list these as filter dropdowns instead of using the search box.

You can make the search more advanced by using Document Library Pro with the SearchWP plugin. This allows you to choose exactly what data is searchable, keep search analytics, search within the content of PDF documents, and more.

Please see the separate article about how to do this.

Search term option

You can also choose to filter the contents of the document table or grid when it is first displayed. To do this, add the search_term option to your shortcode. E.g.

[doc_library search_term="policy"]

Notes:

  1. When using lazy load, the search_term option will only search the document title and content - the other columns will not be searched.
  2. The search is case insensitive.
  3. As with the main WordPress search, the search is done by keyword, not individual words. So if you use search_term="policy1", then it will match documents with the name "policy1", "policy12", "Policy1 - HR", etc.

The search box that appears above the table does not create a URL for each search term because it uses AJAX and displays results on the same page. If you wish to link to a pre-searched table then there are 3 ways to do this:

  • Use the search_term shortcode option (described above) to create a table that is pre-filtered for a specific search term.
  • Generate the URL's using the standalone search box which comes with Posts Table Pro. The search results page for the standalone search box generates a unique URL for each search, so you can link to these URL's as required. This is the format for linking to a specific search term (in this case, we are doing a search for 'policy': https://yourwebsite.com/search-results/?ptp_search=policy (Note: If you have changed the slug for the search results page then you should update search-results in the URL with the new slug.)
  • Use Document Library Pro with the FacetWP plugin, which has URL's for each filter option.

Can I load a pre-filtered table and then allow users to expand the selection to view all documents?

Some people like to use the search_term option to create a pre-filtered table, while giving their users the option to remove the search term and view a wider selection of documents that don't match this keyword.

This is possible if you are using the lazy load option in Document Library Pro. Use the search term option to filter the table by a specific keyword, as described above. Your users can then delete the keyword from the search box. The table will re-load with all possible documents, including those that don't match that keyword.

Please note that this will not work if lazy load is disabled.

Can I search the contents of PDF's or documents in the library?

The search box provided by Document Library Pro cannot search the contents of the attached PDFs or downloadable files. It will index the following information:

  • If you are not using lazy load - The search will read the entire contents of the table/grid, but not the downloadable documents.
  • If you are using lazy load - The search will index the title and the main content area for all the documents displayed in the library - but it can't read the content of the downloadable documents.

These are our suggestions:

  • ​​Instead, of letting people search the contents of documents, you can use categories, tags, or custom taxonomies to label each document with the keywords that people are likely to be searching for (you can create custom taxonomies with the free Easy Post Types and Fields plugin easily). You can then add these as filter dropdowns above the document table, providing an easy way for people to find items with these keywords even though they can't search within the document file itself.
  • Alternatively, use Document Library Pro with the SearchWP plugin (see setup instructions). This allows you to search within the contents of PDF's and certain other file types.

Related Articles

If searching the knowledge base hasn't answered your question, please contact support.