Integration with Simple Custom Post Order

Last updated February 6, 2015 « Knowledge Base

Simple Custom Post Order is a popular plugin that allows you to easily sort the order of various post types in your WordPress install. Unfortunately it interferes with WordPress by applying it’s logic to search results page which can undo the work SearchWP did to present the most relevant results in the proper order. If you are using Simple Custom Post Order you can resolve this issue by preventing Simple Custom Post Order from applying itself on search results pages.

To resolve the conflict with Simple Custom Post Order, add the following to your theme’s functions.php:

<?php
/**
* Simple Custom Post Order prevents SearchWP results from showing, this function removes the problematic
* filters during searches only
*
* @param $wp_query
*
* @return mixed
*/
function my_custom_post_order_searchwp_fix( $wp_query ) {
if ( is_search() && class_exists( 'SCPO_Engine' ) ) {
// unset Simple Page Ordering filters
if ( ! empty( $GLOBALS['wp_filter'] )
&& isset( $GLOBALS['wp_filter']['pre_get_posts'] )
&& ! empty( $GLOBALS['wp_filter']['pre_get_posts'] ) ) {
foreach( $GLOBALS['wp_filter']['pre_get_posts'] as $key => $registered_filters ) {
foreach( $registered_filters as $registered_filter_key => $registered_filter ) {
if ( isset( $registered_filter['function'] )
&& isset( $registered_filter['function'][0] )
&& is_object( $registered_filter['function'][0] )
&& $registered_filter['function'][0] instanceof SCPO_Engine ) {
unset( $GLOBALS['wp_filter']['pre_get_posts'][ $key ][ $registered_filter_key ] );
}
}
}
}
}
return $wp_query;
}
add_filter( 'pre_get_posts', 'my_custom_post_order_searchwp_fix', 999 );
view raw gistfile1.php hosted with ❤ by GitHub
Fix Search on Your Site. No Coding Required!

Now you can utilize all of the content that's gone unrecognized by native WordPress search instantly with SearchWP

Get SearchWP