Solar search in custom product loop

  • leomoon
    Participant
    4 years, 5 months ago #14464

    I have a page that includes a custom product loop that uses wc_get_products function to retrieve desired results.
    It uses the same paging and sorting header as all other archive pages (search, category, taxonomy…)

    This page, however, does not pass any criteria defined in your get_is_replace_front_end function, and so WPSOLR is not used.

    This creates a problem when sorting since sort dropdown, when WPSOLR is active uses different strings (eg _price_str_asc instead of just price) and hence no sorting happens.

    Is there a way to force the use of WPSOLR to retrieve results (and thus presumably get results faster)?

    wpsolr
    Keymaster
    4 years, 5 months ago #14467

    You can notice

    $is_replace_by_wpsolr_query = static::$is_replace_by_wpsolr_query_admin || static::get_is_replace_front_end();
    
    $is_replace_by_wpsolr_query = apply_filters( WPSOLR_Events::WPSOLR_FILTER_IS_REPLACE_BY_WPSOLR_QUERY, $is_replace_by_wpsolr_query );

    Hence returning true when the current page is yours should trigger WPSOLR. But success is not guaranteed then, as WPSOLR is built for archives, with the exception of Toolset Views in next release.

    leomoon
    Participant
    4 years, 5 months ago #14536

    After adding $is_replace_by_wpsolr_query logic to return true in case my custom page is queried, the results are all fine, but for some reason, the page gets rendered down to page.php instead of custom page template (in my case template-new-arrivals.php).

    Any idea why custom template rendering is lost when query is replaced by wpsolr query?

    wpsolr
    Keymaster
    4 years, 5 months ago #14538

    global $wp_query have been replaced with a new query

    I suspect the informations related to the current page template have been lost in the process.

    leomoon
    Participant
    4 years, 5 months ago #14539

    Indeed, that is exactly what happens. Is there a way to preserve this information? It would enable use of WPSolr on custom pages, especially for example on landing pages where every millisecond matters as far as both SEO and user experience is concerned. On my landing page, I list all the new product arrivals, on-sales and fetured products. If all these were displayed via WPSolr, I presume we would gain something in speed.

    wpsolr
    Keymaster
    leomoon
    Participant
    4 years, 5 months ago #14693

    This will work for now, thanks.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.