• Resolved andisman

    (@andisman)


    In short I need to find products where attributes term value should be “LIKE” 100 value. So it should find terms like: 100/104, 100/99.

    My URL search: domain.com/?pa_boltpcd=100

    So I have attribute (pa_boltpcd) which is a taxonomy. This taxonomy (pa_boltpcd) has terms:

    100
    100/104
    100/99

    At the moment it only shows products where term value is exactly “100”. Why where is no such operator “like” which could find all these 3 terms by searching for “100” value.

    What I tried:

    function taxonomy_like( $q ) {
    
    if(isset($q->query['pa_boltpcd'])){
    
        $tax_query = (array) $q->get( 'tax_query' );
    
        $termIds = get_terms([
            'name__like' => '100',
            'fields' => 'ids'
        ]);
    
        $tax_query[] = array(
            'taxonomy' => 'pa_boltpcd',
            'field' => 'term_id',
            'terms' => $termIds,
            'operator' => 'IN'
        );
    
        $q->set( 'tax_query', $tax_query );
    }
    
    }
    add_action( 'woocommerce_product_query', 'taxonomy_like' );

    1. With this hook first I am searching for terms where is value 100 with criteria ‘LIKE’, so it will find all these terms.

    2. Then I collect these founded terms id’s.

    3. After that I am creating tax_query where it could search by my founded id’s.

    BUT the problem is that it returns the same result, and it shows products where term is exactly is 100 …

    Please give me some tips what to do??? Sorry for bad english, correct me where is not clear.

    • This topic was modified 6 years ago by andisman.
    • This topic was modified 6 years ago by andisman.
Viewing 1 replies (of 1 total)
  • Plugin Support Hannah S.L.

    (@fernashes)

    Automattic Happiness Engineer

    Hey there,

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

Viewing 1 replies (of 1 total)
  • The topic ‘Why taxonomy query operator don’t have “LIKE” in WordPress?’ is closed to new replies.