• Resolved denism300

    (@denism300)


    The function WC_Query::get_main_search_query_sql() does not work on search page. It return empty result, but if I remove the argument dgwt_wcas=1 from the browser’s address bar, the function works correctly

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @denism300

    WC_Query::get_main_search_query_sql() returns empty results due to the way of the plugin works. Perhaps we can help solve your problem if you could tell us the context of the use of this function.

    Best Regards
    Kris

    Thread Starter denism300

    (@denism300)

    Hello @c0nst
    I want to add product filters to the search page, but due to the fact that the function WC_Query::get_main_search_query_sql() returns an empty result, they do not work correctly

    Hi again @denism300

    You can try to directly modify the SQL query that is responsible for search results.
    To do that you can use the posts_search filter with higher priority than FiboSearch.

    Here is how FiboSearch uses this filter (with priority 501):

    add_filter( 'posts_search', array( $this, 'searchFilters' ), 501, 2 );

    Example how you can use it (you need to check if you are in FiboSearch context):

    add_filter( 'posts_search', function( $search, $query ) {
    
    	// Interrupt early if you are not in the FiboSearch context
    	if ( ! ( defined( 'DGWT_WCAS_AJAX' ) && DGWT_WCAS_AJAX ) ) {
    		return $search;
    	}
    
    	// Place to modify $search by your own rules
    
    }, 502, 2);

    You can read more about filtering posts_search here: https://developer.www.ads-software.com/reference/hooks/posts_search/

    Regards,
    Kris

    • This reply was modified 3 years, 3 months ago by Kris.
    Thread Starter denism300

    (@denism300)

    ok, thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘The WC function does not work’ is closed to new replies.