• Resolved rochow

    (@rochow)


    I see in the code it mentioned FacetWP compatibility. However, even running latest versions of everything, it’s not filtering the search results AWS returns.

    I have re-run both indexes.

    I have tried every setting possible.

    https://site.com/?s=teddy&post_type=product&type_aws=true

    Shows 8 products.

    Sidebar filter counts look correct. There is colour: red (7), orange (1)

    https://site.com/?s=teddy&post_type=product&type_aws=true&_colour=orange

    Still shows 8 products. This is both via FacetWP AJAX, and when loading above URL directly.

    https://site.com/?s=teddy&post_type=product&_colour=orange

    Will show 1 product as expected.

    https://advanced-woo-search.com/guide/facetwp/

    I don’t see a setting per #2, but it maybe old. Everything looks enabled.

    Playing with the code:

    facetwp_aws_searchpage_enabled() turns false
    facetwp_aws_search_page_custom_data() sets force_ids

    facetwp_pre_filtered_post_ids()
    Array ( [0] => 20623 [1] => 20619 [2] => 20615 [3] => 20611 [4] => 20601 [5] => 20597 [6] => 20593 [7] => 20589 )

    facetwp_filtered_post_ids()
    Array ( [0] => 20593 )

    So it seems alright; it finds 8 products, then does the filtering and has 1 result. But 8 are showing regardless.

    2021 theme + WooCommerce + Facet WP + Advanced Woo Search being the only things active still has the issue.

    Note: With AWS disabled, filtering on search page works. So something with the integration is related.

    Any ideas? Thanks in advance!!!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author ILLID

    (@mihail-barinov)

    Hi,

    Looks like I found the solution for you. Please use following code snippet:

    if (!class_exists('AWS_FacetWP')) :
    
        /**
         * Class for main plugin functions
         */
        class AWS_FacetWP {
    
            /**
             * @var AWS_FacetWP The single instance of the class
             */
            protected static $_instance = null;
    
            private $data = array();
    
            /**
             * Main AWS_FacetWP Instance
             *
             * Ensures only one instance of AWS_FacetWP is loaded or can be loaded.
             *
             * @static
             * @return AWS_FacetWP - Main instance
             */
            public static function instance()
            {
                if (is_null(self::$_instance)) {
                    self::$_instance = new self();
                }
                return self::$_instance;
            }
    
            /**
             * Constructor
             */
            public function __construct() {
    
                add_filter( 'facetwp_filtered_post_ids', array( $this, 'facetwp_filtered_post_ids' ), 1 );
                add_filter( 'aws_searchpage_enabled', array( $this, 'aws_searchpage_enabled' ), 1 );
                add_filter( 'aws_search_page_custom_data', array( $this, 'aws_search_page_custom_data' ), 1 );
                add_filter( 'posts_pre_query', array( $this, 'posts_pre_query' ), 9999, 2 );
    
            }
    
            /*
             * FacetWP check for active filters
             */
            public function facetwp_filtered_post_ids( $post_ids ) {
                if ( isset( $_GET['type_aws'] ) && isset( $_GET['s'] ) && ! empty( $post_ids ) ) {
                    $this->data['facetwp'] = true;
                    $this->data['filtered_post_ids'] = $post_ids;
                }
                return $post_ids;
            }
    
            /*
             * Disable AWS search if FacetWP is active
             */
            public function aws_searchpage_enabled( $enabled ) {
                if ( isset( $this->data['facetwp'] ) && $this->data['facetwp'] ) {
                    $enabled = false;
                }
                return $enabled;
            }
    
            /*
             * FacetWP - Update search page query
             */
            public function aws_search_page_custom_data( $data ) {
                if ( isset( $this->data['facetwp'] ) && $this->data['facetwp'] ) {
                    $data['force_ids'] = true;
                }
                return $data;
            }
    
            /*
             * Update posts query
             */
            public function posts_pre_query( $posts, $query ) {
                if ( isset( $this->data['filtered_post_ids'] ) && ! empty( $this->data['filtered_post_ids'] ) ) {
                    $posts = $this->data['filtered_post_ids'];
                }
                return $posts;
            }
    
        }
    
    endif;
    
    AWS_FacetWP::instance();

    You need to add it somewhere outside the plugins folder. For example, inside functions.php file of your theme or use some plugin for adding code snippets.

    Also the fix will be included to the next plugin version.

    Regards

    Thread Starter rochow

    (@rochow)

    Thanks for that! It looks to work now.

    Plugin Author ILLID

    (@mihail-barinov)

    Glad to help.

    Thread Starter rochow

    (@rochow)

    There is actually a problem with this. The footer menu goes to hell on the search page.

    It looks to work when is_main_query() is checked. Not sure of any adverse side affects, it seems to be good. This makes only the search query be overwritten instead of anything using a query on the page.

    public function posts_pre_query( $posts, $query ) {
    		if ( $query->is_main_query() && isset( $this->data['filtered_post_ids'] ) && ! empty( $this->data['filtered_post_ids'] ) ) {
    			$posts = $this->data['filtered_post_ids'];
    		}
    		return $posts;
    	}
    Plugin Author ILLID

    (@mihail-barinov)

    Thanks. Looks like you are right. Previous code overwrites all queries on the page.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘FacetWP Compatibility’ is closed to new replies.