1. Home
  2. Knowledge Base
  3. Posts Table Pro
  4. Advanced Usage
  5. Adding posts tables to search results

Adding posts tables to search results

Posts Table Pro isn’t really designed to be displayed on search results pages, but you can achieve this with a bit of custom coding.

This article contains general advice about how to display the search results from the built-in WordPress search in a table. This is advanced usage of Posts Table Pro and isn’t covered by our standard plugin support. It should only be attempted by experienced developers.

How to display WordPress search results in a table

To display search results in a table layout, you need to make 2 changes to your theme:

  1. Step 1 – Modify search.php – First, you need to modify the search.php template in your theme. We have created a sample search.php file to get you started – this is designed to work with the Storefront theme, and the exact code for your theme will differ from this. If you don’t know how to adapt it to your own theme, then you will need to ask your developer. Download sample search.php
  2. Step 2 – Add filter – You will also need to add this code to your theme in order for the posts table to work in the search results:

add_filter( 'posts_table_run_in_search', '__return_true' );

The exact implementation will depend on your theme. If you don’t know where to add this code, then you will need to ask your developer.

Customizing the posts table in the search results

The example file includes a table with the default columns and options. Any additional shortcode options can be passed as arguments in the array given to the ‘ptp_the_posts_table’ call. Please see the complete list of Posts Table options.

Getting help

Since this is advanced usage of the plugin, it’s not covered by our standard support. If you don’t have a developer and need any help getting it working, we recommend posting a job on Codeable and their WordPress experts will bid for the work. Alternatively, please get in touch if you’d like a quote from our plugin customizations service.

Was this article helpful?

Related Articles