Quick-and-dirty plugin that allows you to specify custom search results for specific search queries.
Move gg-custom-results.php
into either the /wp-content/plugins/
or /wp-content/mu-plugins/
directory. If you put it in plugins
, you'll need to activate from Plugins menu in the WordPress admin. If you put in mu-plugins
, it will be automatically active.
You can define your custom search results in wp-config.php
. Insert the following just above the line that reads /* That's all, stop editing! Happy blogging. */
:
define( 'GG_CUSTOM_RESULTS', array(
'custom search query' => array( 10, 20 ),
'another query' => array( 11 ),
) );
The key of each item in the array (e.g.: custom search query
) is the query you want to display custom results for. The value (e.g.: array( 10, 20 )
) is an array post (or page) IDs you want to return as custom results. Note that if you only have one ID for a particular query, the user will be redirected straight to that result upon search and the search results page will be skipped entirely.
If the custom results are Custom Post Types, you'll additionally need to ensure that you've configured WordPress to include CPTs in the search results. Here's a good tutorial: https://thomasgriffin.io/how-to-include-custom-post-types-in-wordpress-search-results/