Critical SQL Error Caused by Theme – posts.ID Alias Missing in WP_Query Filters

This topic has 2 replies, 2 voices, and was last updated 2 days, 2 hours ago ago by Samir Malik

  • Avatar: mahdar
    MAHDAR
    Participant
    November 28, 2025 at 22:53

    Hi,
    I’m experiencing a critical issue caused by the theme.
    Even with only WooCommerce and Elementor enabled, my website is generating continuous SQL errors in the log.

    Here is the error:

    WordPress database error Unknown column ‘posts.ID’ in ‘IN/ALL/ANY’

    Example from the error log:

    AND posts.ID IN (
    SELECT tr.object_id
    FROM wp_term_relationships AS tr
    WHERE tr.term_taxonomy_id IN (…)
    )

    The issue seems to come from the theme (or a function inside the theme) modifying the WP_Query and injecting a condition that uses posts.ID.
    However, WordPress uses the default table name wp_posts and no alias named posts exists, which causes MySQL to throw the error “Unknown column ‘posts.ID'”.

    To confirm the source of the problem, I switched the theme to Storefront, and the issue immediately disappeared.
    So the problem is definitely caused by the theme.

    I also tried re-uploading the theme, the theme’s companion plugin, Elementor, and WooCommerce through the hosting panel and extracted them again, but the issue did not get resolved.

    Please review the part of the theme code where filters like posts_where, pre_get_posts, or custom SQL conditions are added.
    The incorrect posts.ID should be replaced with:

    {$wpdb->posts}.ID

    or at minimum:

    wp_posts.ID

    This bug currently breaks multiple queries, including:

    WooCommerce product queries

    Elementor templates

    Elementor Floating Buttons module

    Maintenance Mode templates

    Any frontend WP_Query execution

    Please provide a fix or a patch in the next update, as this issue causes constant SQL errors and affects site functionality.

    This message was written with the help of AI — apologies if any part is unclear.

    Thank you.

    Content is visible for topic creator and
    support staff only.
    1 Answer
    Avatar: Samir Malik
    Samir Malik
    Support staff
    November 30, 2025 at 18:13

    Hello @MAHDAR,

    Could you please provide the steps to reproduce this issue on our end?

    We have tested the search function in the header, and it appears to be working correctly: https://prnt.sc/_XlPpZViv7Y0

    We only found the following error messages related to the WP Rocket plugin in the log files. Please review them in the private content area.

    Best regards,
    8Theme Team

    Content is visible for topic creator and
    support staff only.
  • Viewing 2 results - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.