• Hello,
    this simple plugin really rocks. Worked flawlessly.

    I would suggest a small implementation that could help in some cases where attributes names are formed by multiple string.

    If people switch one of the words or forget one. Results are zero.

    In my case I had an attribute made of people, the name of the terms was people’s Surname and Name.
    Anyone searching switching Name and Surname in search would have zero results.

    So I’ve edited the plugin, to allow a search for each word just when looking for the attribute I needed:

    function wsatt_brands_where( $where = '' ) {
    global $wpdb;

    $wsatt_attributes = get_option( 'wsatt_attributes' );
    if ( isset( $wsatt_attributes ) && is_array( $wsatt_attributes ) && count( $wsatt_attributes ) > 0 ) {
    foreach ( $wsatt_attributes as $attribute ) {
    $where .= " OR $wpdb->posts.ID IN (SELECT $wpdb->posts.ID
    FROM $wpdb->posts
    LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
    WHERE $wpdb->posts.post_type = 'product'
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->term_taxonomy.taxonomy = '" . esc_sql( $attribute ) . "'
    AND $wpdb->terms.name LIKE '%" . get_search_query() . "%')";
    // if the attribute is "peoples"
    if ( $attribute = 'pa_people' ){
    // search for each word in the search query
    $words = explode( ' ', get_search_query() );
    foreach ( $words as $word ) {
    $where .= " OR $wpdb->posts.ID IN (SELECT $wpdb->posts.ID
    FROM $wpdb->posts
    LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
    WHERE $wpdb->posts.post_type = 'product'
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->term_taxonomy.taxonomy = '" . esc_sql( $attribute ) . "'
    AND $wpdb->terms.name LIKE '%" . $word . "%')";

    }

    }
    // end the attribute is "peoples"
    }
    }

    return $where;
    }
    }

    I’ve just added the lines between:

    // if the attribute is “peoples”
    and
    // end the attribute is “peoples”

    And it does the trick.

    Maybe an additional option for each enabled Attribute, to broaden searches on specific attribute terms names would be a nice addition to this nice plugin ??

    Thanks.

  • The topic ‘Search for each word separately’ is closed to new replies.