• Resolved Aleksander Eerma

    (@alexeerma)


    Hello!
    Right now the relevanssi search is not working. Im not really sure what i need to switch wp_query with. Right now i want it to search by _skus also. The admin search works but on frontend it doesn’t.

    search.php is following.

    get_header(); ?>
    <?php
        global $query_string;
    
        $big = 999999;
    
        $query_args = explode("&", $query_string);
        $search_query = array( 's' => 'keyword' );
    
        foreach($query_args as $key => $string) {
          $query_split = explode("=", $string);
          $search_query[$query_split[0]] = urldecode($query_split[1]);
        } // foreach
    
        $the_query = new WP_Query($search_query);
        if ( $the_query->have_posts() ) : 
        ?> 
        <!-- the loop -->
        <?php
        global $wp_query;
        $total_results = $wp_query->found_posts;
    ?>
    
    <div id="pageContent">  
        <div class="container">
            <div class="row">
                <div class="col-12">
                    <p class="lead text-center"><?php esc_html_e( 'Leidsime kokku ', 'brandweb-child'); ?> <strong><?php echo $total_results; ?></strong> <?php esc_html_e( 'otsingutulemused', 'brandweb-child'); ?>.</p>
                </div>
            </div>
            <div class="row d-flex align-items-stretch">
                <?php 
                while ( $the_query->have_posts() ) : $the_query->the_post();
                 get_template_part('library/partials/blog/regular-blog-layout');     
                endwhile; ?>
                <div class="col-12 mt-md-5 mt-3">
                    <?php 
                        echo paginate_links( array(
                        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                        'format' => '?paged=%#%',
                        'current' => max( 1, get_query_var('paged') ),
                        'total' => $wp_query->max_num_pages
                    ) );
                    ?>
                </div>
            </div>
        </div>
    </div>
    
    <?php wp_reset_postdata(); ?>
    
    <?php else : ?>
    
        <div id="pageContent">  
            <div class="container">
                <div class="row">
                    <div class="col-12">
                        <p><?php esc_html_e( 'Teie otsingul ei olnud tulemusi.', 'brandweb-child'); ?>.</p>
                        <p><?php esc_html_e( 'Proovige uuesti m?ne muu m?rks?naga', 'brandweb-child' ); ?></p>
                        <?php get_search_form(); ?>
                    </div>
                </div>
            </div> 
        </div> 
    
    <?php endif; ?>
    
    <?php get_footer(); ?>

    Looking forward for the help!

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

    (@msaari)

    $search_query = array( 's' => 'keyword', 'relevanssi' => true );

    That’s all it should take.

    Thread Starter Aleksander Eerma

    (@alexeerma)

    Thank you for the reply!
    So after reindexing it does respond to different words, but still no answer when searching by sku. (I’ve added the custom _sku field to be indexed)

    I do get the response for sku from admin search.

    Any ideas?

    Plugin Author Mikko Saari

    (@msaari)

    What are you adding to the search query in addition to the search term? Does it work if you only add the SKU in s?

    Thread Starter Aleksander Eerma

    (@alexeerma)

    Im only searching just for the SKU nothing else added. For example “413”.
    But in further investigation it seems that for some reason it’s not showing the search results for the search term either. For example if im searching for “stend”. I have a product that has “stend” included in product name and it does not show either.

    Thread Starter Aleksander Eerma

    (@alexeerma)

    Got it to work, had to remove a filter I added to functions.php beforehand.

    Thanks for the help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Relevanssi search not working on custom search’ is closed to new replies.