Site logo

[Resolved] Search not working

Home Forums Support [Resolved] Search not working

Home Forums Support Search not working

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #2596343
    Scott

    Dunno if this is a theme issue or a WP issue. But the ONLY search that works is the Woocommerce Product Search block and ONLY returns products. No other search block returns anything at all and just leads to a 404 page (which ironically has a search feature that also returns nothing). The navigation search thing also returns nothing.

    /wp-content/themes/generatepress/assets/js/menu.min.js
    /wp-content/themes/generatepress/assets/js/navigation-search.min.js
    /wp-content/gp-premium/menu-plus/functions/js/offside.min.js

    have all been excluded from WP-Rocket optimizations.

    So I can search products … but Pages & Posts are not searched.

    #2596686
    Ying
    Staff
    Customer Support

    hi there,

    I just tested the search2 link you attached, and it works normally.

    Have you tried testing it on another device?

    Let me know!

    #2596751
    Scott

    No I haven’t but I will and report back.

    #2596755
    Scott

    Doesn’t work on a different device or different web connection.

    #2596781
    Ying
    Staff
    Customer Support

    Can you disable all plugins except Woo and GP Premium?

    If you are using a child theme, can you switch to the parent theme?

    Let me know how it goes.

    #2597210
    Scott

    I found the issue. It’s this code snippet used to hide a product category from search results.

    /* Remove Product Category from Search */
    function remove_cat_from_search ( $q ) {
       if (!is_admin() && $q->is_main_query() && $q->is_search()) {
           $q->set( 'post_type', array( 'product' ) );
           $tax_query = (array) $q->get( 'tax_query' );
        $tax_query[] = array(
               'taxonomy' => 'product_cat',
               'field' => 'slug',
               'terms' => array( 'castlerockrehab','medicalsolutions' ), //no t-shirts in search
               'operator' => 'NOT IN'
        );
        $q->set( 'tax_query', $tax_query );
        
        }
    }
    add_action( 'pre_get_posts', 'remove_cat_from_search' );

    which really sucks as I need this functionality 😔

    #2597222
    Fernando
    Customer Support

    Hi Scott,

    To clarify, do you also want Posts to appear aside from Products when searching?

    #2597278
    Scott

    Ideally posts, pages, and products is what I’d prefer.

    #2597290
    Fernando
    Customer Support

    Can you try replacing the code you have with this?:

    add_action( 'pre_get_posts', function( $query ) {
      if( ! is_admin() && is_search() && $query->is_main_query() ) {
        $query->set( 'post_type', array( 'page', 'post', 'product' ) );
        $tax_query = (array) $query->get( 'tax_query' );
        $tax_query[] = array(
               'taxonomy' => 'product_cat',
               'field' => 'slug',
               'terms' => array( 'castlerockrehab','medicalsolutions' ), //no t-shirts in search
               'operator' => 'NOT IN'
        );
        $query->set( 'tax_query', $tax_query );
      }
    } );
    #2597316
    Scott

    Like a charm. This isxwhy you guys and gals are the bestest!

    #2597325
    Fernando
    Customer Support

    You’re welcome, Scott!

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.