Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/ad4f85720c6b19b76dcf to your computer and use it in GitHub Desktop.
Save jchristopher/ad4f85720c6b19b76dcf to your computer and use it in GitHub Desktop.
Fixes Simple Custom Post Order and SearchWP
<?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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment