Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter digitalgreg

    (@digitalgreg)

    Hi, I found the solution myself.
    I’ve downloaded the database and found out that TheCartPress stores the sku as a custom field in postmeta table.

    I’ve came across how to add custom fields to search results and I did.
    You need to modify fuctions.php with the following code:

    add_filter('posts_where', 'advanced_search_query' );
    
    function advanced_search_query( $where )
    {
      if( is_search() ) {
    
        global $wpdb;
        $query = get_search_query();
        $query = like_escape( $query );
    
        // include postmeta in search
         $where .=" OR {$wpdb->posts}.ID IN (SELECT {$wpdb->postmeta}.post_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->postmeta}.meta_key = 'tcp_sku' AND {$wpdb->postmeta}.meta_value LIKE '%$query%' AND {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)";
    
        if(WP_DEBUG)var_dump($where);
        }
        return $where;
    }

    Hope that will help somebody else

Viewing 1 replies (of 1 total)