Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.