Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Honestly not sure what to suggest here. The end goal is to have a search page that is beyond just domain.com/?s=search_term that’s powered by Algolia?

    Thread Starter datakitanih

    (@datakitanih)

    Hi Michael @tw2113,

    That’s right, the final destination is domain.com/search/?s=search_term
    I created a custom template with a custom display for search results.
    But always get 404 when Algolia is enabled.

    When I deleted my custom code and went back to domain.com/?s=search_term, it worked.

    Can you help me why this happens?
    It’s as if Algolia doesn’t accept custom slug parameters

    Thanks

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Extra question to help me dig into some things. Are you using the “Use Algolia with the native WordPress search template” setting?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Going on the assumption of yes, you’re wanting to use Algolia with the native search template, my hunches are that it’s this snippet of code that’s preventing things from working for you:

    private function should_filter_query( WP_Query $query ) {
    	$should_filter = ! $query->is_admin && $query->is_search() && $query->is_main_query();
    
    	/**
    	 * Allow developers to override the return value of should_filter_query().
    	 *
    	 * @since  1.3.0
    	 *
    	 * @param bool     $should_filter Whether Algolia should filter the search query.
    	 * @param WP_Query $query         The WP_Query that was tested for Algolia Search filtering.
    	 */
    	return (bool) apply_filters(
    		'algolia_should_filter_query',
    		$should_filter,
    		$query
    	);
    }

    Most specifically, either the $query->is_search() part, the $query->is_main_query() or both.

    Since you’re creating a custom template, I’m hunching you’re also creating a custom WP_Query instance to do the searching?

    Worth using the filter and some guard if statements to conditionally return true for a given query. How to best do that, I can’t say offhand as I’ve never tried to do a custom search template at a URL like this.

    Github version: https://github.com/WebDevStudios/wp-search-with-algolia/blob/main/includes/class-algolia-search.php#L66-L92

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Slug Search Result Page’ is closed to new replies.