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.
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 send you a quote. We have partnered with them to provide plugin customizations for our customers.
Can I use Posts Table Pro with third party search plugins?
The instructions and sample template on the page will only work with the search facility that comes with WordPress itself.
You can use Posts Table Pro with third party search plugins such as Relevanssi or SearchWP. To do this, you would need to add the Posts Table Pro shortcode to the search results template provided by Relevanssi, so that people can type into the Relevanssi search box and view the results in a document library table layout.
As mentioned above, this is a developer-level task and if you don’t have a developer already then you can find a good one on Codeable.