• Resolved speshiou

    (@speshiou)


    After upgrading to 4.5.1, using attribute filters can cause db error.

    Steps:
    1. Add multiple attribute filters with ‘OR’ condition to shop sidebar
    2. Navigate to the pages with specific product category, ex: https://example.com/product-category/category1
    3. Click one of tax term to filter
    4. DB Error occurs

    
    SELECT COUNT(DISTINCT(product_id)) AS term_count, term_count_id
    FROM (
    SELECT IF(wp_posts.post_type='product_variation', wp_posts.post_parent, wp_posts.ID) AS product_id, terms.term_id AS term_count_id
    FROM wp_posts
    INNER JOIN wp_term_relationships AS tr
    ON wp_posts.ID = tr.object_id
    INNER JOIN wp_term_taxonomy AS term_taxonomy USING( term_taxonomy_id )
    INNER JOIN wp_terms AS terms USING( term_id )
    LEFT JOIN wp_term_relationships
    ON (wp_posts.ID = wp_term_relationships.object_id)
    LEFT JOIN wp_term_relationships AS tt1
    ON (wp_posts.ID = tt1.object_id)
    WHERE wp_posts.post_status = 'publish'
    AND ( wp_term_relationships.term_taxonomy_id IN (24)
    AND wp_posts.ID NOT IN (
    SELECT object_id
    FROM wp_term_relationships
    WHERE term_taxonomy_id IN (7,9) )
    AND tt1.term_taxonomy_id IN (98) )
    AND ( ( wp_posts.post_type = 'product'
    AND ( wp_posts.ID NOT IN (
    SELECT object_id
    FROM wp_term_relationships
    WHERE term_taxonomy_id IN (4) ) ) )
    OR (wp_posts.post_type = 'product_variation'
    AND NOT EXISTS (
    SELECT ID
    FROM wp_posts AS parent
    WHERE parent.ID = wp_posts.post_parent
    AND parent.post_status NOT IN ('publish') )) )
    AND terms.term_id IN (31,32,33,34,35)
    UNION ALL
    SELECT wp_posts.ID AS product_id, wp_term_relationships.term_taxonomy_id as term_count_id
    FROM wp_posts JOIN wp_posts variations
    ON variations.post_parent = wp_posts.ID
    LEFT JOIN wp_postmeta
    ON variations.ID = wp_postmeta.post_id
    AND wp_postmeta.meta_key = 'attribute_pa_color' JOIN wp_term_relationships
    ON wp_term_relationships.object_id = wp_posts.ID
    WHERE ( wp_postmeta.meta_key IS NULL
    OR wp_postmeta.meta_value = '')
    AND wp_posts.post_type = 'product'
    AND wp_posts.post_status = 'publish'
    AND variations.post_status = 'publish'
    AND variations.post_type = 'product_variation'
    AND wp_term_relationships.term_taxonomy_id in (31,32,33,34,35)
    AND ( wp_term_relationships.term_taxonomy_id IN (24)
    AND wp_posts.ID NOT IN (
    SELECT object_id
    FROM wp_term_relationships
    WHERE term_taxonomy_id IN (7,9) )
    AND tt1.term_taxonomy_id IN (98) ) ) AS x
    GROUP BY term_count_id
    

    Error message

    
    Unknown column 'tt1.term_taxonomy_id' in 'where clause'
    
    • This topic was modified 4 years, 6 months ago by speshiou.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Grigorij S. a11n

    (@grigaswp)

    Hi @speshiou,

    Thank you for reaching out!

    I understand that with WooCommerce 4.5.1, when a “filter products by attribute” widget with multiple attributes and “or” condition is used – a database error occurs.

    Can you please specify if you are adding multiple widgets with different attributes or you are simply selecting multiple terms of a single attribute (within a single widget)? Perhaps you are using a third-party plugin? Feel free to add screenshots of the setup.

    Our developers attempted to hide out of stock variations when “Filter Products by Attribute” widget is used but this change broke too many things:

    https://github.com/woocommerce/woocommerce/issues/27419#issuecomment-689657524

    In version 4.5.1, the “Filter products by attribute” widget is not yet fixed which means that variable products are not displayed by the widget and there might be other issues.

    It looks like in an upcoming version of WooCommerce, the old functionality will be reverted.

    Right now, you could solve this by reverting to version 4.3.1 and that can be done using WP Rollback plugin.

    Thread Starter speshiou

    (@speshiou)

    I added two “filter products by attribute” widgets with different attributes to shop sidebar, I think they are official woocommerce widgets.

    View post on imgur.com

    And the DB error occurred when every time I clicked on the terms.

    Since DB migration came with version 4.5.1, what if I revert to old version? Will it cause DB corruption?

    Plugin Support Grigorij S. a11n

    (@grigaswp)

    Hi there,

    I added two “filter products by attribute” widgets with different attributes to shop sidebar, I think they are official woocommerce widgets.

    View post on imgur.com

    And the DB error occurred when every time I clicked on the terms.

    Thank you for confirming! While we are able to replicate non-working widgets, we are unable to replicate the database error on our test sites.

    Since DB migration came with version 4.5.1, what if I revert to old version? Will it cause DB corruption?

    I’m not aware of how exactly WP Rollback plugin works and if it reverts the database version as well.

    There is always a chance of things going wrong during a downgrade so I’d suggest making sure you have a functioning site backup and perhaps also a database backup.

    I hope this helps!

    Plugin Support Grigorij S. a11n

    (@grigaswp)

    Hi there,

    We haven’t heard from you in a while so I’ll be marking this thread as resolved.

    Feel free to open a new thread and link to this one if you have further questions though.

    Have a wonderful day ahead!

    Thread Starter speshiou

    (@speshiou)

    This issue has been fixed in 4.5.2.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘DB Error caused by using multiple attribute filters after upgrading to 4.5.1’ is closed to new replies.