• Resolved obnova

    (@obnova)


    Is posible set up in setings – search only in title not in description of product.

    thanx

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author algol.plus

    (@algolplus)

    Hello

    you can try this code. WARNING, probably you should tweak it.
    thanks, Alex

    add_filter( "wpo_custom_product_search", function($results,$query_args,$term) {
     global $wpdb;
     $term = esc_sql($wpdb->esc_like($term));
     $results = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type='product' AND post_status='publish' AND post_title LIKE '%{$term}%' ORDER BY post_title LIMIT 25");
     return $results;
    },10,3);
    Thread Starter obnova

    (@obnova)

    Thanx a lot.
    And when i want to search in title and also in sku?

    Plugin Author algol.plus

    (@algolplus)

    Updated version (+ SKU)

    add_filter( "wpo_custom_product_search", function($results,$query_args,$term) {
     global $wpdb;
     $term = esc_sql($wpdb->esc_like($term));
     $results = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type='product' AND post_status='publish' AND post_title LIKE '%{$term}%'  
                               OR ID IN (SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value LIKE '%{$term}%' )
                               ORDER BY post_title LIMIT 25");
     return $results;
    },10,3);
    
    Thread Starter obnova

    (@obnova)

    Perfect! Thanx.

    Plugin Author algol.plus

    (@algolplus)

    you’re welcome

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Search only in title’ is closed to new replies.