• Hi Team,

    I have added one custom search form to search under a specific parent page and for that, I am adding a filter to manipulate query. But when I enable the solr plugin, I got results from the whole site instead of pages under a specific parent page.

    /*
    * Custom Search results
    */
    function custom_searchfilter( $query ) {
    	if ( $query->is_search){
    		$query->set('solr_integrate', true);
    	}
    
    	if ( $query->is_search && isset( $_GET['search-type'] ) ) {
    		$parent_page       = filter_input( INPUT_GET, 'search-type', FILTER_SANITIZE_STRING );
    		$parent_page_array = explode( ', ', $parent_page );
    		// print_r($parent_page_array);
    		$query->set( 'post_parent__in', $parent_page_array );
    		// $query->set( 'post_parent', 246 );
    	}
    	return $query;
    }
    add_filter( 'pre_get_posts', 'custom_searchfilter' );

    I think plugin does not support the default filters of search.
    Please suggest me a way to accomplish this.

    Thanks

  • The topic ‘pre_get_posts for search results not working after activating plugin’ is closed to new replies.