Plugin can break queries that use custom post types
-
The plugin function
blog_search_filtercauses problems when using aWP_Querythat contains a search term. The filter overrides thepost_typefield withanyeven when a WordPress search wasn’t made. This means searches that are narrowed to a custom post type will include everything.Quick example (when the plugin is enabled):
// Create a query to find pages. $my_query = new WP_Query(array( 'post_type' => 'page', 's' => 'search term', ) ); // This will echo "any", but it should be "page". echo $my_query->query_vars['post_type'];One potential fix is to only override the post type when it’s set in the url:
// Replace lines 78-81 of "osd-blog-search-widget.php" with // the following: if ( $post_type ) { $query->set( 'post_type', $post_type ); }An alternative would be to include an additional hidden field on the form (like
osd_blog_searchor similar) and then only change the post type when that is set to true.Thank you!
The topic ‘Plugin can break queries that use custom post types’ is closed to new replies.