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

Adding posts tables to search results

Although Posts Table Pro isn’t designed to be displayed on search results pages, you can achieve this by modifying the search template in your theme.

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.

How to display WordPress search results in a table

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.

In this file you will see the following line:

add_filter( 'posts_table_run_in_search', '__return_true' );

This ensures that the posts table will work on the search results page.

You will then see a call to the ptp_the_posts_table function. This displays the table using the posts from the current search. You could also add extra options here, passing these to the ptp_the_posts_table. This function takes the same attributes and options as the posts table shortcode.

The exact implementation will depend on your theme. You will most likely need to modify the HTML structure to match the other templates in your theme.

Customizing the posts table in the search results

The example file includes a table with the default columns and options set in the plugin settings. Any additional shortcode options can be passed as arguments in the array given to the call to ptp_the_posts_table. 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