A member of the MSTW family experienced the following problem with his site search results. (WordPress native search) The MSTW Schedules & Scoreboards plugin* makes use of a number of “custom post types” (CPTs), as do all the MSTW plugins. These CPTs, such as games in the case of MSTW S&S, will show up in the search results. For example, if all the soccer games have ‘soccer’ in their titles (not unreasonable), then the CPTs for all soccer games will appear in the results. This might be okay, except I did not create a template to display the scheduled_game
CPT, because that was not necessary for the plugin’s functionality. (The MSTW League Manager plugin DOES have a template to display games, so this is not an issue.)
There are many ways to ‘fix’ issue if it’s a problem for you. I found a great post by AJ Clark of WPExplorer that describes some possible fixes. WP Search is just a WP database query at the end of the day, and WordPress provides many ways to ‘filter’ queries (== jump in the middle of them).
Richard Cardona shared the following code snippet that you can drop into your (hopefully child) theme’s functions.php
.
add_action( 'init', 'remove_a_custom_type', 99 ); function remove_a_custom_type() { global $wp_post_types; if ( post_type_exists( 'scheduled_games' ) ) { // exclude from search results $wp_post_types['scheduled_games']->exclude_from_search = true; } }
As always, if you have questions or comments, please post them to the appropriate support forum(s) so other users can benefit from you question and its answer.
* The MSTW Schedules & Scoreboards plugin is no longer supported, it has been replaced by the MSTW League Manager plugin. However these concepts apply to the entire MSTW plugin family.