Plugin can break queries that use custom post types
-
The plugin function
blog_search_filter
causes problems when using aWP_Query
that contains a search term. The filter overrides thepost_type
field withany
even 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_search
or 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.