Fixes Simple Custom Post Order and SearchWP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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