加入2个表格订单WordPress插件

时间:2019-12-07 作者:l3lmk

我有两张表格wp\\u wcfm\\u marketplace\\u orderswp\\u wcfm\\u affiliate\\u orders

我需要wp\\u wcfm\\u affiliate\\u订购的呼叫数据。orderid wp\\u wcfm\\u marketplace\\u订单。order\\u identer image description here

it代码调用数据表wp\\U wcfm\\U affiliate\\U orders

    public function processing() {
        global $WCFM, $wpdb, $_POST, $WCFMu, $WCFMaf;

        $length = $_POST[\'length\'];
        $offset = $_POST[\'start\'];

        $affiliate_id = $_POST[\'wcfm_affiliate\']; 
        $status          = $_POST[\'status_type\'];

        $sql  = "SELECT COUNT(ID) FROM `{$wpdb->prefix}wcfm_affiliate_orders`";
        $sql .= " WHERE 1=1";
        $sql .= " AND {$wpdb->prefix}wcfm_affiliate_orders.affiliate_id = {$affiliate_id}";
        if( $status ) $sql .= " AND {$wpdb->prefix}wcfm_affiliate_orders.commission_status = \'{$status}\'";
        $sql .= \' AND `is_trashed` = 0\';
        $affiliate_count = $wpdb->get_var( $sql );

        // Get Product Count
        $sql  = "SELECT  * FROM  {$wpdb->prefix}wcfm_affiliate_orders  ";
        $sql .= " WHERE 1=1";
        $sql .= " AND {$wpdb->prefix}wcfm_affiliate_orders.affiliate_id = {$affiliate_id} 

        ";
        if( $status ) $sql .= " AND {$wpdb->prefix}wcfm_affiliate_orders.commission_status = \'{$status}\'";
        $sql .= \' AND `is_trashed` = 0\';
        $sql .= " ORDER BY `ID` DESC";
        $sql .= " LIMIT {$length}";
        $sql .= " OFFSET {$offset}";


        $wcfm_affiliate_orders_array = $wpdb->get_results( $sql );
        $wcfm_affiliate_order_count  = count( $wcfm_affiliate_orders_array );

1 个回复
最合适的回答,由SO网友:l3lmk 整理而成

//获取产品计数$sql=“选择wcfm\\u affiliate\\u orders。*,ya.order\\u id,ya.order\\u status FROM{$wpdb->prefix}wcfm\\u affiliate\\u orders AS wcfm\\u affiliate\\u orders LEFT JOIN{$wpdb->prefix}wcfm\\u marketplace\\u orders AS ya.order\\u id=wcfm\\u affiliate\\u orders.order\\u id”$sql.=“其中1=1”$sql.=“和wcfm\\u affiliate\\u orders.affiliate\\u id={$affiliate\\u id}

    ";
    if( $status ) $sql .= " AND  wcfm_affiliate_orders.commission_status = \'{$status}\'";

    $sql .= " ORDER BY  wcfm_affiliate_orders.ID  DESC";
    $sql .= " LIMIT {$length}";
    $sql .= " OFFSET {$offset}";


    $wcfm_affiliate_orders_array = $wpdb->get_results( $sql );