Skip to content

Instantly share code, notes, and snippets.

@jkudish
Created November 28, 2023 03:26
Show Gist options
  • Save jkudish/e5cd9254abfa4e4903dd837c72513c8f to your computer and use it in GitHub Desktop.
Save jkudish/e5cd9254abfa4e4903dd837c72513c8f to your computer and use it in GitHub Desktop.
Minimum code to reproduce a bug in EDD's database query when performing an Order query containing a date_query and a product_id at the same time
<?php
/**
* Plugin Name: Edd Database Bug Reproduction
* Plugin URI:
* Description: Reproduce a bug in EDD's database query.
* Author: Joey Kudish
* Author URI: https://github.com/jkudish
* Text Domain: edd-database-bug
* Domain Path: /languages
* Version: 0.1.0
*
* @package Edd_Database_Bug
*/
if ( defined( 'WP_CLI' ) && WP_CLI ) {
class EDD_Order_DB_Query_bug extends WP_CLI_Command {
/**
* Reproduce a bug in EDD's database query.
* Database error when performing an Order query containing a date_query and a product_id at the same time
*
* [--product_id=<product_id>]
* : Filter by a specific product ID
*
* @param array $args Positional arguments.
* @param array $assoc_args Associative arguments.
*/
public function __invoke( $args, $assoc_args ) {
$query = array(
'product_id' => $assoc_args['product_id'],
'date_query' => array(
array(
'after' => '2023-11-01 00:00:00',
'before' => '',
'inclusive' => true,
),
),
);
// this will produce a database error:
// WordPress database error Column 'date_created' in where clause is ambiguous for query SELECT ...
// this is due to the JOIN on the order items table
$orders = edd_get_orders( $query );
}
}
WP_CLI::add_command( 'edd-bug', 'EDD_Order_DB_Query_bug' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment