Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Ollie Tiger

    (@ollieandtiger)

    @tw2113 This is illuminating info on the inner workings. I’m going to play around with this a bit and see if I can figure out where the sticking point is. Since it’s become a bit tricky, my client may be deprioritizing this for now (though may come back to it again at some point), but I will follow up if I find anything else interesting here. I know this is a pretty edge case use. Regardless the plugin is working superbly and I would recommend it to anyone. Thanks again for taking the time here to contribute to the knowledge base and help me out!

    • This reply was modified 1 year, 2 months ago by Ollie Tiger.
    Thread Starter Ollie Tiger

    (@ollieandtiger)

    @tw2113 Ah I thought for sure this would solve it, but alas, the result is the same.

    <?php
    add_action( 'pre_get_posts', function( $query ) {
    if ( ! is_admin() && $query->is_main_query() ) {
    if ( isset( $_REQUEST['q'] ) && ! empty( $_REQUEST['q'] ) ) {
    // Set the search query
    $query->set( 's', sanitize_text_field( $_REQUEST['q'] ) );
    $query->is_search = true;
    }
    }
    },9);

    I think it is very odd that it shows a random post as well as a totally random counter which are the same regardless of the search terms. Any ideas what that might be a clue to?

    P.s. Thanks for taking the time to help out here.

    Thread Starter Ollie Tiger

    (@ollieandtiger)

    Hi @tw2113,

    Thanks for getting back to me!

    I’m using native search, not Instantsearch.

    Here’s a snippet of what I had working with other search providers:

    <?php
    add_action( 'pre_get_posts', function( $query ) {
    if ( ! is_admin() && $query->is_main_query() ) {
    if ( isset( $_REQUEST['q'] ) && ! empty( $_REQUEST['q'] ) ) {
    // Set the search query
    $query->set( 's', sanitize_text_field( $_REQUEST['q'] ) );
    $query->is_search = true;
    }
    }
    });

    Here we check that the query is not admin, is main query, and then set is_search = true after making the change from s to q. So it seems like it should be passing all of the tests in the code you shared, and $should_filter should be true and the results should be handled by Algolia?

    The current behavior is very strange, and when I enable this code the counter results show a random very large number and only one post is displayed. The number and post are the same regardless of search terms. So strange.

    Edit: I should mention also that the form was changed to be using q for the label as well instead of s.

Viewing 3 replies - 1 through 3 (of 3 total)