Skip to content

SQL error: Unknown column when WooCommerce is active - table alias not used in comments filter #2904

@Vr00mm

Description

@Vr00mm

WP Job Manager Applications - Bug Report

Describe the bug

When WooCommerce is installed alongside WP Job Manager Applications, SQL errors occur because the plugin uses $wpdb->posts.post_type in a WHERE clause, but WooCommerce aliases the posts table as wp_posts_to_exclude_reviews in its comment count queries. Once a table is aliased in SQL, the original table name is no longer valid in that query scope.

The error appears in includes/class-wp-job-manager-applications-dashboard.php:

$where .= " $wpdb->posts.post_type NOT IN ('job_application') ";

This produces SQL errors like:

Unknown column 'wp_posts.post_type' in 'WHERE' for query SELECT COUNT(*)
FROM wp_comments LEFT JOIN wp_posts AS wp_posts_to_exclude_reviews ON comment_post_ID = wp_posts_to_exclude_reviews.ID 
WHERE ... AND wp_posts_to_exclude_reviews.post_type NOT IN ('product') AND wp_posts.post_type NOT IN ('job_application')

To Reproduce

  1. Install and activate WooCommerce
  2. Install and activate WP Job Manager and WP Job Manager Applications
  3. Go to wp-admin dashboard or any admin page
  4. Check PHP error logs - SQL errors appear on every page load

Screenshots

N/A - error visible in server logs

Expected behavior

No SQL errors. The filter should use a method that works regardless of table aliasing, such as a subquery:

$where .= " AND comment_post_ID NOT IN (SELECT ID FROM $wpdb->posts WHERE post_type = 'job_application') ";

Isolating the problem (mark completed items with an [x]):

  • I have deactivated other plugins and confirmed this bug occurs when only WP Job Manager plugin is active.
  • This bug happens with a default WordPress theme active.
  • I can reproduce this bug consistently using the steps above.

WordPress Environment

  • WordPress Version: 6.x
  • WP Job Manager Version: latest
  • WP Job Manager Applications Version: latest
  • WooCommerce Version: 9.x
  • PHP Version: 8.x
  • Other important details: The bug is a conflict between WP Job Manager Applications and WooCommerce's WC_Comments::wp_count_comments filter which aliases the posts table.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions