$where = ''; $join = ''; switch ($post_type) { default: $where .= " and {$wpdb->postmeta}.meta_key='item_id' and {$wpdb->postmeta}.meta_value={$item_id}"; break; } $query = "SELECT count({$wpdb->posts}.ID) as total from {$wpdb->posts}\r\n join {$wpdb->postmeta} on {$wpdb->posts}.ID={$wpdb->postmeta}.post_id\r\n join {$wpdb->postmeta} as tbl2 on tbl2.post_id={$wpdb->posts}.ID\r\n {$join}\r\n where 1=1"; $query .= " and `post_type`='st_order' "; $query .= " and {$wpdb->posts}.post_status='publish'\r\n and {$wpdb->postmeta}.meta_key='item_id'\r\n\r\n "; $query .= $where; $query .= " and tbl2.meta_key='id_user'\r\n AND tbl2.meta_value='{$user_id}'"; $count = $wpdb->get_var($query); return $count; } function init_metabox() { //Room $this->metabox[] = array('id' => 'order_metabox', 'title' => __('Order Setting', ST_TEXTDOMAIN), 'desc' => '', 'pages' => array('st_order'), 'context' => 'normal', 'priority' => 'high', 'fields' => array(array('label' => __('General', ST_TEXTDOMAIN), 'id' => 'order_reneral_tab', 'type' => 'tab'), array('label' => __('Total Price', ST_TEXTDOMAIN), 'id' => 'total_price', 'type' => 'text'), array('label' => __('Customer', ST_TEXTDOMAIN), 'id' => 'id_user', 'type' => 'user_select_ajax'), array('label' => __('Request Booking', ST_TEXTDOMAIN), 'id' => 'st_o_note', 'type' => 'textarea_simple'), array('label' => __('Payment Method', ST_TEXTDOMAIN), 'id' => 'payment_method', 'type' => 'select', 'choices' => array(array('label' => __('Paypal', ST_TEXTDOMAIN), 'value' => 'paypal'), array('label' => __('Submit Form', ST_TEXTDOMAIN), 'value' => 'submit_form')), 'std' => 'submit_form'))); } static function get_order_id_by_token($token) { global $wpdb; $query = "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='order_token_code' AND meta_value=%s LIMIT 0,1"; $r = $wpdb->get_var($wpdb->prepare($query, $token)); return $r; } } $a = new STOrder(); $a->init(); }