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.
To display search results in a table layout, you need to make 2 changes to your theme:
Step 1 – Modify search.php
can 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.
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.
Customising the posts table
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. You can read about all the options elsewhere in this knowledge base.
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 customisations service.