本文整理汇总了PHP中WP_Date_Query::get_sql方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Date_Query::get_sql方法的具体用法?PHP WP_Date_Query::get_sql怎么用?PHP WP_Date_Query::get_sql使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Date_Query
的用法示例。
在下文中一共展示了WP_Date_Query::get_sql方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
//.........这里部分代码省略.........
$approved = "( comment_approved = '0' OR comment_approved = '1' )";
}
$order = 'ASC' == strtoupper($order) ? 'ASC' : 'DESC';
if (!empty($orderby)) {
$ordersby = is_array($orderby) ? $orderby : preg_split('/[,\\s]/', $orderby);
$allowed_keys = array('comment_agent', 'comment_approved', 'comment_author', 'comment_author_email', 'comment_author_IP', 'comment_author_url', 'comment_content', 'comment_date', 'comment_date_gmt', 'comment_ID', 'comment_karma', 'comment_parent', 'comment_post_ID', 'comment_type', 'user_id');
if (!empty($this->query_vars['meta_key'])) {
$allowed_keys[] = $this->query_vars['meta_key'];
$allowed_keys[] = 'meta_value';
$allowed_keys[] = 'meta_value_num';
}
$ordersby = array_intersect($ordersby, $allowed_keys);
foreach ($ordersby as $key => $value) {
if ($value == $this->query_vars['meta_key'] || $value == 'meta_value') {
$ordersby[$key] = "{$wpdb->commentmeta}.meta_value";
} elseif ($value == 'meta_value_num') {
$ordersby[$key] = "{$wpdb->commentmeta}.meta_value+0";
}
}
$orderby = empty($ordersby) ? 'comment_date_gmt' : implode(', ', $ordersby);
} else {
$orderby = 'comment_date_gmt';
}
$number = absint($number);
$offset = absint($offset);
if (!empty($number)) {
if ($offset) {
$limits = 'LIMIT ' . $offset . ',' . $number;
} else {
$limits = 'LIMIT ' . $number;
}
} else {
$limits = '';
}
if ($count) {
$fields = 'COUNT(*)';
} else {
$fields = '*';
}
$join = '';
$where = $approved;
if (!empty($post_id)) {
$where .= $wpdb->prepare(' AND comment_post_ID = %d', $post_id);
}
if ('' !== $author_email) {
$where .= $wpdb->prepare(' AND comment_author_email = %s', $author_email);
}
if ('' !== $karma) {
$where .= $wpdb->prepare(' AND comment_karma = %d', $karma);
}
if ('comment' == $type) {
$where .= " AND comment_type = ''";
} elseif ('pings' == $type) {
$where .= ' AND comment_type IN ("pingback", "trackback")';
} elseif (!empty($type)) {
$where .= $wpdb->prepare(' AND comment_type = %s', $type);
}
if ('' !== $parent) {
$where .= $wpdb->prepare(' AND comment_parent = %d', $parent);
}
if ('' !== $user_id) {
$where .= $wpdb->prepare(' AND user_id = %d', $user_id);
}
if ('' !== $search) {
$where .= $this->get_search_sql($search, array('comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content'));
}
$post_fields = array_filter(compact(array('post_author', 'post_name', 'post_parent', 'post_status', 'post_type')));
if (!empty($post_fields)) {
$join = "JOIN {$wpdb->posts} ON {$wpdb->posts}.ID = {$wpdb->comments}.comment_post_ID";
foreach ($post_fields as $field_name => $field_value) {
$where .= $wpdb->prepare(" AND {$wpdb->posts}.{$field_name} = %s", $field_value);
}
}
if (!empty($this->meta_query->queries)) {
$clauses = $this->meta_query->get_sql('comment', $wpdb->comments, 'comment_ID', $this);
$join .= $clauses['join'];
$where .= $clauses['where'];
$groupby = "{$wpdb->comments}.comment_ID";
}
if (!empty($date_query) && is_array($date_query)) {
$date_query_object = new WP_Date_Query($date_query, 'comment_date');
$where .= $date_query_object->get_sql();
}
$pieces = array('fields', 'join', 'where', 'orderby', 'order', 'limits', 'groupby');
$clauses = apply_filters_ref_array('comments_clauses', array(compact($pieces), &$this));
foreach ($pieces as $piece) {
${$piece} = isset($clauses[$piece]) ? $clauses[$piece] : '';
}
if ($groupby) {
$groupby = 'GROUP BY ' . $groupby;
}
$query = "SELECT {$fields} FROM {$wpdb->comments} {$join} WHERE {$where} {$groupby} ORDER BY {$orderby} {$order} {$limits}";
if ($count) {
return $wpdb->get_var($query);
}
$comments = $wpdb->get_results($query);
$comments = apply_filters_ref_array('the_comments', array($comments, &$this));
wp_cache_add($cache_key, $comments, 'comment');
return $comments;
}
示例2: get_comment_ids
//.........这里部分代码省略.........
$this->sql_clauses['where']['user_id'] = 'user_id IN (' . implode(',', array_map('absint', $this->query_vars['user_id'])) . ')';
} elseif ('' !== $this->query_vars['user_id']) {
$this->sql_clauses['where']['user_id'] = $wpdb->prepare('user_id = %d', $this->query_vars['user_id']);
}
if ('' !== $this->query_vars['search']) {
$search_sql = $this->get_search_sql($this->query_vars['search'], array('comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content'));
// Strip leading 'AND'.
$this->sql_clauses['where']['search'] = preg_replace('/^\\s*AND\\s*/', '', $search_sql);
}
// If any post-related query vars are passed, join the posts table.
$join_posts_table = false;
$plucked = wp_array_slice_assoc($this->query_vars, array('post_author', 'post_name', 'post_parent', 'post_status', 'post_type'));
$post_fields = array_filter($plucked);
if (!empty($post_fields)) {
$join_posts_table = true;
foreach ($post_fields as $field_name => $field_value) {
// $field_value may be an array.
$esses = array_fill(0, count((array) $field_value), '%s');
$this->sql_clauses['where']['post_fields'] = $wpdb->prepare(" {$wpdb->posts}.{$field_name} IN (" . implode(',', $esses) . ')', $field_value);
}
}
// Comment author IDs for an IN clause.
if (!empty($this->query_vars['author__in'])) {
$this->sql_clauses['where']['author__in'] = 'user_id IN ( ' . implode(',', wp_parse_id_list($this->query_vars['author__in'])) . ' )';
}
// Comment author IDs for a NOT IN clause.
if (!empty($this->query_vars['author__not_in'])) {
$this->sql_clauses['where']['author__not_in'] = 'user_id NOT IN ( ' . implode(',', wp_parse_id_list($this->query_vars['author__not_in'])) . ' )';
}
// Post author IDs for an IN clause.
if (!empty($this->query_vars['post_author__in'])) {
$join_posts_table = true;
$this->sql_clauses['where']['post_author__in'] = 'post_author IN ( ' . implode(',', wp_parse_id_list($this->query_vars['post_author__in'])) . ' )';
}
// Post author IDs for a NOT IN clause.
if (!empty($this->query_vars['post_author__not_in'])) {
$join_posts_table = true;
$this->sql_clauses['where']['post_author__not_in'] = 'post_author NOT IN ( ' . implode(',', wp_parse_id_list($this->query_vars['post_author__not_in'])) . ' )';
}
$join = '';
if ($join_posts_table) {
$join .= "JOIN {$wpdb->posts} ON {$wpdb->posts}.ID = {$wpdb->comments}.comment_post_ID";
}
if (!empty($this->meta_query_clauses)) {
$join .= $this->meta_query_clauses['join'];
// Strip leading 'AND'.
$this->sql_clauses['where']['meta_query'] = preg_replace('/^\\s*AND\\s*/', '', $this->meta_query_clauses['where']);
if (!$this->query_vars['count']) {
$groupby = "{$wpdb->comments}.comment_ID";
}
}
$date_query = $this->query_vars['date_query'];
if (!empty($date_query) && is_array($date_query)) {
$date_query_object = new WP_Date_Query($date_query, 'comment_date');
$this->sql_clauses['where']['date_query'] = preg_replace('/^\\s*AND\\s*/', '', $date_query_object->get_sql());
}
$where = implode(' AND ', $this->sql_clauses['where']);
$pieces = array('fields', 'join', 'where', 'orderby', 'limits', 'groupby');
/**
* Filter the comment query clauses.
*
* @since 3.1.0
*
* @param array $pieces A compacted array of comment query clauses.
* @param WP_Comment_Query &$this Current instance of WP_Comment_Query, passed by reference.
*/
$clauses = apply_filters_ref_array('comments_clauses', array(compact($pieces), &$this));
$fields = isset($clauses['fields']) ? $clauses['fields'] : '';
$join = isset($clauses['join']) ? $clauses['join'] : '';
$where = isset($clauses['where']) ? $clauses['where'] : '';
$orderby = isset($clauses['orderby']) ? $clauses['orderby'] : '';
$limits = isset($clauses['limits']) ? $clauses['limits'] : '';
$groupby = isset($clauses['groupby']) ? $clauses['groupby'] : '';
$this->filtered_where_clause = $where;
if ($where) {
$where = 'WHERE ' . $where;
}
if ($groupby) {
$groupby = 'GROUP BY ' . $groupby;
}
if ($orderby) {
$orderby = "ORDER BY {$orderby}";
}
$found_rows = '';
if (!$this->query_vars['no_found_rows']) {
$found_rows = 'SQL_CALC_FOUND_ROWS';
}
$this->sql_clauses['select'] = "SELECT {$found_rows} {$fields}";
$this->sql_clauses['from'] = "FROM {$wpdb->comments} {$join}";
$this->sql_clauses['groupby'] = $groupby;
$this->sql_clauses['orderby'] = $orderby;
$this->sql_clauses['limits'] = $limits;
$this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}";
if ($this->query_vars['count']) {
return intval($wpdb->get_var($this->request));
} else {
$comment_ids = $wpdb->get_col($this->request);
return array_map('intval', $comment_ids);
}
}
示例3: prepare_query
//.........这里部分代码省略.........
if (isset($qv['blog_id'])) {
$blog_id = absint($qv['blog_id']);
}
if (isset($qv['who']) && 'authors' == $qv['who'] && $blog_id) {
$qv['meta_key'] = $wpdb->get_blog_prefix($blog_id) . 'user_level';
$qv['meta_value'] = 0;
$qv['meta_compare'] = '!=';
$qv['blog_id'] = $blog_id = 0;
// Prevent extra meta query
}
// Meta query.
$this->meta_query = new WP_Meta_Query();
$this->meta_query->parse_query_vars($qv);
$role = '';
if (isset($qv['role'])) {
$role = trim($qv['role']);
}
if ($blog_id && ($role || is_multisite())) {
$cap_meta_query = array();
$cap_meta_query['key'] = $wpdb->get_blog_prefix($blog_id) . 'capabilities';
if ($role) {
$cap_meta_query['value'] = '"' . $role . '"';
$cap_meta_query['compare'] = 'like';
}
if (empty($this->meta_query->queries)) {
$this->meta_query->queries = array($cap_meta_query);
} elseif (!in_array($cap_meta_query, $this->meta_query->queries, true)) {
// Append the cap query to the original queries and reparse the query.
$this->meta_query->queries = array('relation' => 'AND', array($this->meta_query->queries, $cap_meta_query));
}
$this->meta_query->parse_query_vars($this->meta_query->queries);
}
if (!empty($this->meta_query->queries)) {
$clauses = $this->meta_query->get_sql('user', $wpdb->users, 'ID', $this);
$this->query_from .= $clauses['join'];
$this->query_where .= $clauses['where'];
if ('OR' == $this->meta_query->relation) {
$this->query_fields = 'DISTINCT ' . $this->query_fields;
}
}
// sorting
$qv['order'] = isset($qv['order']) ? strtoupper($qv['order']) : '';
$order = $this->parse_order($qv['order']);
if (empty($qv['orderby'])) {
// Default order is by 'user_login'.
$ordersby = array('user_login' => $order);
} else {
if (is_array($qv['orderby'])) {
$ordersby = $qv['orderby'];
} else {
// 'orderby' values may be a comma- or space-separated list.
$ordersby = preg_split('/[,\\s]+/', $qv['orderby']);
}
}
$orderby_array = array();
foreach ($ordersby as $_key => $_value) {
if (!$_value) {
continue;
}
if (is_int($_key)) {
// Integer key means this is a flat array of 'orderby' fields.
$_orderby = $_value;
$_order = $order;
} else {
// Non-integer key means this the key is the field and the value is ASC/DESC.
$_orderby = $_key;
示例4: get
public static function get($args = array(), $output = OBJECT)
{
global $wpdb;
$query = wp_parse_args($args);
$query_length = count($query);
$i = 1;
$table = XBooking_BOOKING_TABLE;
$where = $query_length > 0 ? 'WHERE ' : '';
foreach ($query as $column => $value) {
if ($column == 'date_query') {
$query_args = array(array('column' => 'date', 'before' => $value['before'], 'inclusive' => true), array('column' => 'date', 'after' => $value['after'], 'inclusive' => true));
$date_query = new WP_Date_Query($query_args, 'date');
$where .= $date_query->get_sql();
// Reduce counter as get_sql produces 'AND' for us
$i--;
} else {
$where .= "{$column} = '{$value}' ";
}
$i++;
}
$select = "SELECT * FROM {$table} {$where} ORDER BY date DESC";
// If unique value queried only get single row
if (isset($query['id'])) {
$results = $wpdb->get_row($select, $output);
} else {
$results = $wpdb->get_results($select, $output);
}
return !empty($results) ? $results : false;
}
示例5: get_commissions
/**
* Get Commissions
*
* @param array $q
*
* @return array
* @author Andrea Grillo <andrea.grillo@yithemes.com>
* @since 1.0
*/
public function get_commissions($q = array())
{
global $wpdb;
$default_args = array('line_item_id' => 0, 'product_id' => 0, 'order_id' => 0, 'user_id' => 0, 'vendor_id' => 0, 'status' => 'unpaid', 'm' => false, 'date_query' => false, 's' => '', 'number' => '', 'offset' => '', 'paged' => '', 'orderby' => 'ID', 'order' => 'ASC', 'fields' => 'ids');
foreach (array('order_id', 'vendor_id', 'status', 'paged', 'm', 's', 'orderby', 'order', 'product_id') as $key) {
if (isset($_REQUEST[$key])) {
$default_args[$key] = $_REQUEST[$key];
}
}
$q = wp_parse_args($q, $default_args);
// Fairly insane upper bound for search string lengths.
if (!is_scalar($q['s']) || !empty($q['s']) && strlen($q['s']) > 1600) {
$q['s'] = '';
}
// First let's clear some variables
$where = '';
$limits = '';
$join = '';
$groupby = '';
$orderby = '';
// query parts initializating
$pieces = array('where', 'groupby', 'join', 'orderby', 'limits');
// filter
if (!empty($q['line_item_id'])) {
$where .= $wpdb->prepare(" AND c.line_item_id = %d", $q['line_item_id']);
}
if (!empty($q['product_id'])) {
$join .= " JOIN {$wpdb->prefix}woocommerce_order_items oi ON ( oi.order_item_id = c.line_item_id AND oi.order_id = c.order_id )";
$join .= " JOIN {$wpdb->prefix}woocommerce_order_itemmeta oim ON ( oim.order_item_id = oi.order_item_id )";
$where .= $wpdb->prepare(" AND oim.meta_key = %s AND oim.meta_value = %s", '_product_id', $q['product_id']);
}
if (!empty($q['order_id'])) {
$where .= $wpdb->prepare(" AND c.order_id = %d", $q['order_id']);
}
if (!empty($q['user_id'])) {
$where .= $wpdb->prepare(" AND c.user_id = %d", $q['user_id']);
}
if (!empty($q['vendor_id'])) {
$where .= $wpdb->prepare(" AND c.vendor_id = %d", $q['vendor_id']);
}
if (!empty($q['status']) && 'all' != $q['status']) {
if (is_array($q['status'])) {
$q['status'] = implode("', '", $q['status']);
}
$where .= sprintf(" AND c.status IN ( '%s' )", $q['status']);
}
// The "m" parameter is meant for months but accepts datetimes of varying specificity
if ($q['m']) {
$q['m'] = absint(preg_replace('|[^0-9]|', '', $q['m']));
$join .= strpos($join, "{$wpdb->posts} o") === false ? " JOIN {$wpdb->posts} o ON o.ID = c.order_id" : '';
$where .= " AND o.post_type = 'shop_order'";
$where .= " AND YEAR(o.post_date)=" . substr($q['m'], 0, 4);
if (strlen($q['m']) > 5) {
$where .= " AND MONTH(o.post_date)=" . substr($q['m'], 4, 2);
}
if (strlen($q['m']) > 7) {
$where .= " AND DAYOFMONTH(o.post_date)=" . substr($q['m'], 6, 2);
}
if (strlen($q['m']) > 9) {
$where .= " AND HOUR(o.post_date)=" . substr($q['m'], 8, 2);
}
if (strlen($q['m']) > 11) {
$where .= " AND MINUTE(o.post_date)=" . substr($q['m'], 10, 2);
}
if (strlen($q['m']) > 13) {
$where .= " AND SECOND(o.post_date)=" . substr($q['m'], 12, 2);
}
}
// Handle complex date queries
if (!empty($q['date_query'])) {
$join .= strpos($join, "{$wpdb->posts} o") === false ? " JOIN {$wpdb->posts} o ON o.ID = c.order_id" : '';
$where .= " AND o.post_type = 'shop_order'";
$date_query = new WP_Date_Query($q['date_query'], 'o.post_date');
$where .= $date_query->get_sql();
}
// Search
if ($q['s']) {
// added slashes screw with quote grouping when done early, so done later
$q['s'] = stripslashes($q['s']);
// there are no line breaks in <input /> fields
$q['s'] = str_replace(array("\r", "\n"), '', $q['s']);
// order
$join .= strpos($join, "{$wpdb->posts} o") === false ? " JOIN {$wpdb->posts} o ON o.ID = c.order_id" : '';
// product
$join .= strpos($join, 'woocommerce_order_items') === false ? " JOIN {$wpdb->prefix}woocommerce_order_items oi ON ( oi.order_item_id = c.line_item_id AND oi.order_id = c.order_id )" : '';
$where .= " AND oi.order_item_type = 'line_item'";
// user
$join .= " JOIN {$wpdb->users} u ON u.ID = c.user_id";
$join .= " JOIN {$wpdb->usermeta} um ON um.user_id = c.user_id";
$join .= " JOIN {$wpdb->usermeta} um2 ON um2.user_id = c.user_id";
$where .= " AND um.meta_key = 'first_name'";
//.........这里部分代码省略.........
示例6: query
//.........这里部分代码省略.........
$where[] = $wpdb->prepare('user_id = %d', $this->query_vars['user_id']);
}
if ('' !== $this->query_vars['search']) {
$search_sql = $this->get_search_sql($this->query_vars['search'], array('comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content'));
// Strip leading 'AND'.
$where[] = preg_replace('/^\\s*AND\\s*/', '', $search_sql);
}
// If any post-related query vars are passed, join the posts table.
$join_posts_table = false;
$plucked = wp_array_slice_assoc($this->query_vars, array('post_author', 'post_name', 'post_parent', 'post_status', 'post_type'));
$post_fields = array_filter($plucked);
if (!empty($post_fields)) {
$join_posts_table = true;
foreach ($post_fields as $field_name => $field_value) {
$where[] = $wpdb->prepare(" {$wpdb->posts}.{$field_name} = %s", $field_value);
}
}
// Comment author IDs for an IN clause.
if (!empty($this->query_vars['author__in'])) {
$where[] = 'user_id IN ( ' . implode(',', wp_parse_id_list($this->query_vars['author__in'])) . ' )';
}
// Comment author IDs for a NOT IN clause.
if (!empty($this->query_vars['author__not_in'])) {
$where[] = 'user_id NOT IN ( ' . implode(',', wp_parse_id_list($this->query_vars['author__not_in'])) . ' )';
}
// Post author IDs for an IN clause.
if (!empty($this->query_vars['post_author__in'])) {
$join_posts_table = true;
$where[] = 'post_author IN ( ' . implode(',', wp_parse_id_list($this->query_vars['post_author__in'])) . ' )';
}
// Post author IDs for a NOT IN clause.
if (!empty($this->query_vars['post_author__not_in'])) {
$join_posts_table = true;
$where[] = 'post_author NOT IN ( ' . implode(',', wp_parse_id_list($this->query_vars['post_author__not_in'])) . ' )';
}
if ($join_posts_table) {
$join = "JOIN {$wpdb->posts} ON {$wpdb->posts}.ID = {$wpdb->comments}.comment_post_ID";
}
if (!empty($this->meta_query->queries)) {
$clauses = $this->meta_query->get_sql('comment', $wpdb->comments, 'comment_ID', $this);
$join .= $clauses['join'];
// Strip leading 'AND'.
$where[] = preg_replace('/^\\s*AND\\s*/', '', $clauses['where']);
if (!$this->query_vars['count']) {
$groupby = "{$wpdb->comments}.comment_ID";
}
}
$date_query = $this->query_vars['date_query'];
if (!empty($date_query) && is_array($date_query)) {
$date_query_object = new WP_Date_Query($date_query, 'comment_date');
$where[] = preg_replace('/^\\s*AND\\s*/', '', $date_query_object->get_sql());
}
$where = implode(' AND ', $where);
$pieces = array('fields', 'join', 'where', 'orderby', 'order', 'limits', 'groupby');
/**
* Filter the comment query clauses.
*
* @since 3.1.0
*
* @param array $pieces A compacted array of comment query clauses.
* @param WP_Comment_Query &$this Current instance of WP_Comment_Query, passed by reference.
*/
$clauses = apply_filters_ref_array('comments_clauses', array(compact($pieces), &$this));
$fields = isset($clauses['fields']) ? $clauses['fields'] : '';
$join = isset($clauses['join']) ? $clauses['join'] : '';
$where = isset($clauses['where']) ? $clauses['where'] : '';
$orderby = isset($clauses['orderby']) ? $clauses['orderby'] : '';
$order = isset($clauses['order']) ? $clauses['order'] : '';
$limits = isset($clauses['limits']) ? $clauses['limits'] : '';
$groupby = isset($clauses['groupby']) ? $clauses['groupby'] : '';
if ($where) {
$where = 'WHERE ' . $where;
}
if ($groupby) {
$groupby = 'GROUP BY ' . $groupby;
}
if ($orderby) {
$orderby = "ORDER BY {$orderby} {$order}";
}
$this->request = "SELECT {$fields} FROM {$wpdb->comments} {$join} {$where} {$groupby} {$orderby} {$limits}";
if ($this->query_vars['count']) {
return $wpdb->get_var($this->request);
}
if ('ids' == $this->query_vars['fields']) {
$this->comments = $wpdb->get_col($this->request);
return array_map('intval', $this->comments);
}
$results = $wpdb->get_results($this->request);
/**
* Filter the comment query results.
*
* @since 3.1.0
*
* @param array $results An array of comments.
* @param WP_Comment_Query &$this Current instance of WP_Comment_Query, passed by reference.
*/
$comments = apply_filters_ref_array('the_comments', array($results, &$this));
wp_cache_add($cache_key, $comments, 'comment');
return $comments;
}
示例7: get_following
/**
* Get the IDs that a user is following.
*
* @since 1.0.0
*
* @param int $user_id The user ID.
* @param string $follow_type The follow type. Leave blank to query users.
* @param array $query_args {
* Various query arguments
* @type array $date_query See {@link WP_Date_Query}.
* @type string $orderby The DB column to order results by. Default: 'id'.
* @type string $order The order. Either 'ASC' or 'DESC'. Default: 'DESC'.
* }
* @return array
*/
public static function get_following($user_id = 0, $follow_type = '', $query_args = array())
{
global $wpdb;
// SQL statement
$sql = self::get_select_sql('leader_id');
$sql .= self::get_where_sql(array('follower_id' => $user_id, 'follow_type' => $follow_type));
// Setup date query
if (!empty($query_args['date_query']) && class_exists('WP_Date_Query')) {
add_filter('date_query_valid_columns', array(__CLASS__, 'register_date_column'));
$date_query = new WP_Date_Query($query_args['date_query'], 'date_recorded');
$sql .= $date_query->get_sql();
remove_filter('date_query_valid_columns', array(__CLASS__, 'register_date_column'));
}
// Setup orderby query
$orderby = array();
if (!empty($query_args['orderby'])) {
$orderby = $query_args['orderby'];
}
if (!empty($query_args['order'])) {
$orderby = $query_args['order'];
}
$sql .= self::get_orderby_sql($orderby);
// do the query
$result = $wpdb->get_col($sql);
// if query args is empty, cache the count while we're here
if (empty($query_args)) {
$type = !empty($follow_type) ? "{$follow_type}_" : "";
wp_cache_set($user_id, $wpdb->num_rows, "bp_follow_following_{$type}count");
}
return $result;
}
示例8: array
//.........这里部分代码省略.........
if (strlen($q['m']) > 7) {
$where .= " AND DAYOFMONTH({$this->network_posts}.post_date)=" . substr($q['m'], 6, 2);
}
if (strlen($q['m']) > 9) {
$where .= " AND HOUR({$this->network_posts}.post_date)=" . substr($q['m'], 8, 2);
}
if (strlen($q['m']) > 11) {
$where .= " AND MINUTE({$this->network_posts}.post_date)=" . substr($q['m'], 10, 2);
}
if (strlen($q['m']) > 13) {
$where .= " AND SECOND({$this->network_posts}.post_date)=" . substr($q['m'], 12, 2);
}
}
if ('' !== $q['hour']) {
$where .= " AND HOUR({$this->network_posts}.post_date)='" . $q['hour'] . "'";
}
if ('' !== $q['minute']) {
$where .= " AND MINUTE({$this->network_posts}.post_date)='" . $q['minute'] . "'";
}
if ('' !== $q['second']) {
$where .= " AND SECOND({$this->network_posts}.post_date)='" . $q['second'] . "'";
}
if ($q['year']) {
$where .= " AND YEAR({$this->network_posts}.post_date)='" . $q['year'] . "'";
}
if ($q['monthnum']) {
$where .= " AND MONTH({$this->network_posts}.post_date)='" . $q['monthnum'] . "'";
}
if ($q['day']) {
$where .= " AND DAYOFMONTH({$this->network_posts}.post_date)='" . $q['day'] . "'";
}
if (isset($q['date_query'])) {
$date_query = new WP_Date_Query($q['date_query'], 'wp_network_posts.post_date');
$where .= $date_query->get_sql();
}
// If we've got a post_type AND its not "any" post_type.
if (!empty($q['post_type']) && 'any' != $q['post_type']) {
foreach ((array) $q['post_type'] as $_post_type) {
$ptype_obj = get_post_type_object($_post_type);
if (!$ptype_obj || !$ptype_obj->query_var || empty($q[$ptype_obj->query_var])) {
continue;
}
if (!$ptype_obj->hierarchical || strpos($q[$ptype_obj->query_var], '/') === false) {
// Non-hierarchical post_types & parent-level-hierarchical post_types can directly use 'name'
$q['name'] = $q[$ptype_obj->query_var];
} else {
// Hierarchical post_types will operate through the
$q['pagename'] = $q[$ptype_obj->query_var];
$q['name'] = '';
}
// Only one request for a slug is possible, this is why name & pagename are overwritten above.
break;
}
//end foreach
unset($ptype_obj);
}
if ('' != $q['name']) {
$q['name'] = sanitize_title_for_query($q['name']);
$where .= " AND {$this->network_posts}.post_name = '" . $q['name'] . "'";
} elseif ('' != $q['pagename']) {
if (isset($this->queried_object_id)) {
$reqpage = $this->queried_object_id;
} else {
if ('page' != $q['post_type']) {
foreach ((array) $q['post_type'] as $_post_type) {
$ptype_obj = get_post_type_object($_post_type);
示例9: get_following
/**
* Get the IDs that a user is following.
*
* @since 1.0.0
*
* @param int $user_id The user ID.
* @param string $follow_type The follow type. Leave blank to query users.
* @param array $query_args {
* Various query arguments
* @type array $date_query See {@link WP_Date_Query}.
* @type string $orderby The DB column to order results by. Default: 'id'.
* @type string $order The order. Either 'ASC' or 'DESC'. Default: 'DESC'.
* }
* @return array
*/
public static function get_following($user_id = 0, $follow_type = '', $query_args = array())
{
global $wpdb;
// SQL statement
$sql = self::get_select_sql('leader_id');
$sql .= self::get_where_sql(array('follower_id' => $user_id, 'follow_type' => $follow_type));
// Setup date query
if (!empty($query_args['date_query']) && class_exists('WP_Date_Query')) {
add_filter('date_query_valid_columns', array(__CLASS__, 'register_date_column'));
$date_query = new WP_Date_Query($query_args['date_query'], 'date_recorded');
$sql .= $date_query->get_sql();
remove_filter('date_query_valid_columns', array(__CLASS__, 'register_date_column'));
}
// Setup orderby query
$orderby = array();
if (!empty($query_args['orderby'])) {
$orderby = $query_args['orderby'];
}
if (!empty($query_args['order'])) {
$orderby = $query_args['order'];
}
$sql .= self::get_orderby_sql($orderby);
// do the query
return $wpdb->get_col($sql);
}
示例10: array
//.........这里部分代码省略.........
}
if (strlen($q['m']) > 11) {
$where .= " AND MINUTE({$wpdb->posts}.post_date)=" . substr($q['m'], 10, 2);
}
if (strlen($q['m']) > 13) {
$where .= " AND SECOND({$wpdb->posts}.post_date)=" . substr($q['m'], 12, 2);
}
}
// Handle the other individual date parameters
$date_parameters = array();
if ('' !== $q['hour']) {
$date_parameters['hour'] = $q['hour'];
}
if ('' !== $q['minute']) {
$date_parameters['minute'] = $q['minute'];
}
if ('' !== $q['second']) {
$date_parameters['second'] = $q['second'];
}
if ($q['year']) {
$date_parameters['year'] = $q['year'];
}
if ($q['monthnum']) {
$date_parameters['monthnum'] = $q['monthnum'];
}
if ($q['w']) {
$date_parameters['week'] = $q['w'];
}
if ($q['day']) {
$date_parameters['day'] = $q['day'];
}
if ($date_parameters) {
$date_query = new WP_Date_Query(array($date_parameters));
$where .= $date_query->get_sql();
}
unset($date_parameters, $date_query);
// Handle complex date queries
if (!empty($q['date_query'])) {
$this->date_query = new WP_Date_Query($q['date_query']);
$where .= $this->date_query->get_sql();
}
// If we've got a post_type AND it's not "any" post_type.
if (!empty($q['post_type']) && 'any' != $q['post_type']) {
foreach ((array) $q['post_type'] as $_post_type) {
$ptype_obj = get_post_type_object($_post_type);
if (!$ptype_obj || !$ptype_obj->query_var || empty($q[$ptype_obj->query_var])) {
continue;
}
if (!$ptype_obj->hierarchical || strpos($q[$ptype_obj->query_var], '/') === false) {
// Non-hierarchical post_types & parent-level-hierarchical post_types can directly use 'name'
$q['name'] = $q[$ptype_obj->query_var];
} else {
// Hierarchical post_types will operate through the
$q['pagename'] = $q[$ptype_obj->query_var];
$q['name'] = '';
}
// Only one request for a slug is possible, this is why name & pagename are overwritten above.
break;
}
//end foreach
unset($ptype_obj);
}
if ('' != $q['name']) {
$q['name'] = sanitize_title_for_query($q['name']);
$where .= " AND {$wpdb->posts}.post_name = '" . $q['name'] . "'";
} elseif ('' != $q['pagename']) {
示例11:
/**
* Inject the date_query SQL in SearchWP's WHERE
*
* @since 2.6
*
* @param $sql
* @param $engine
*
* @return string
*/
function date_where($sql, $engine)
{
if ($engine != $this->engine || empty($this->date_query) || !is_array($this->date_query)) {
return $sql;
}
$date_query = new WP_Date_Query((array) $this->date_query);
$dq_sql = $date_query->get_sql();
return $sql . $dq_sql;
}
示例12: prepare_query
//.........这里部分代码省略.........
if ($wild) {
$search = trim($search, '*');
}
$search_columns = array();
if ($qv['search_columns']) {
$search_columns = array_intersect($qv['search_columns'], array('ID', 'user_login', 'user_email', 'user_url', 'user_nicename'));
}
if (!$search_columns) {
if (false !== strpos($search, '@')) {
$search_columns = array('user_email');
} elseif (is_numeric($search)) {
$search_columns = array('user_login', 'ID');
} elseif (preg_match('|^https?://|', $search) && !(is_multisite() && wp_is_large_network('users'))) {
$search_columns = array('user_url');
} else {
$search_columns = array('user_login', 'user_nicename');
}
}
/**
* Filter the columns to search in a WP_User_Query search.
*
* The default columns depend on the search term, and include 'user_email',
* 'user_login', 'ID', 'user_url', and 'user_nicename'.
*
* @since 3.6.0
*
* @param array $search_columns Array of column names to be searched.
* @param string $search Text being searched.
* @param WP_User_Query $this The current WP_User_Query instance.
*/
$search_columns = apply_filters('user_search_columns', $search_columns, $search, $this);
$this->query_where .= $this->get_search_sql($search, $search_columns, $wild);
}
$blog_id = 0;
if (isset($qv['blog_id'])) {
$blog_id = absint($qv['blog_id']);
}
if (isset($qv['who']) && 'authors' == $qv['who'] && $blog_id) {
$qv['meta_key'] = $wpdb->get_blog_prefix($blog_id) . 'user_level';
$qv['meta_value'] = 0;
$qv['meta_compare'] = '!=';
$qv['blog_id'] = $blog_id = 0;
// Prevent extra meta query
}
$meta_query = new WP_Meta_Query();
$meta_query->parse_query_vars($qv);
$role = '';
if (isset($qv['role'])) {
$role = trim($qv['role']);
}
if ($blog_id && ($role || is_multisite())) {
$cap_meta_query = array();
$cap_meta_query['key'] = $wpdb->get_blog_prefix($blog_id) . 'capabilities';
if ($role) {
$cap_meta_query['value'] = '"' . $role . '"';
$cap_meta_query['compare'] = 'like';
}
if (empty($meta_query->queries)) {
$meta_query->queries = array($cap_meta_query);
} elseif (!in_array($cap_meta_query, $meta_query->queries, true)) {
// Append the cap query to the original queries and reparse the query.
$meta_query->queries = array('relation' => 'AND', array($meta_query->queries, $cap_meta_query));
}
$meta_query->parse_query_vars($meta_query->queries);
}
if (!empty($meta_query->queries)) {
$clauses = $meta_query->get_sql('user', $wpdb->users, 'ID', $this);
$this->query_from .= $clauses['join'];
$this->query_where .= $clauses['where'];
if ('OR' == $meta_query->relation) {
$this->query_fields = 'DISTINCT ' . $this->query_fields;
}
}
if (!empty($include)) {
// Sanitized earlier.
$ids = implode(',', $include);
$this->query_where .= " AND {$wpdb->users}.ID IN ({$ids})";
} elseif (!empty($qv['exclude'])) {
$ids = implode(',', wp_parse_id_list($qv['exclude']));
$this->query_where .= " AND {$wpdb->users}.ID NOT IN ({$ids})";
}
// Date queries are allowed for the user_registered field.
if (!empty($qv['date_query']) && is_array($qv['date_query'])) {
$date_query = new WP_Date_Query($qv['date_query'], 'user_registered');
$this->query_where .= $date_query->get_sql();
}
/**
* Fires after the WP_User_Query has been parsed, and before
* the query is executed.
*
* The passed WP_User_Query object contains SQL parts formed
* from parsing the given query.
*
* @since 3.1.0
*
* @param WP_User_Query $this The current WP_User_Query instance,
* passed by reference.
*/
do_action_ref_array('pre_user_query', array(&$this));
}
示例13: query
//.........这里部分代码省略.........
// Parse comment IDs for an IN clause.
if (!empty($this->query_vars['comment__in'])) {
$where .= ' AND comment_ID IN ( ' . implode(',', wp_parse_id_list($this->query_vars['comment__in'])) . ' )';
}
// Parse comment IDs for a NOT IN clause.
if (!empty($this->query_vars['comment__not_in'])) {
$where .= ' AND comment_ID NOT IN ( ' . implode(',', wp_parse_id_list($this->query_vars['comment__not_in'])) . ' )';
}
// Parse comment post IDs for an IN clause.
if (!empty($this->query_vars['post__in'])) {
$where .= ' AND comment_post_ID IN ( ' . implode(',', wp_parse_id_list($this->query_vars['post__in'])) . ' )';
}
// Parse comment post IDs for a NOT IN clause.
if (!empty($this->query_vars['post__not_in'])) {
$where .= ' AND comment_post_ID NOT IN ( ' . implode(',', wp_parse_id_list($this->query_vars['post__not_in'])) . ' )';
}
if ('' !== $this->query_vars['author_email']) {
$where .= $wpdb->prepare(' AND comment_author_email = %s', $this->query_vars['author_email']);
}
if ('' !== $this->query_vars['karma']) {
$where .= $wpdb->prepare(' AND comment_karma = %d', $this->query_vars['karma']);
}
if ('comment' == $this->query_vars['type']) {
$where .= " AND comment_type = ''";
} elseif ('pings' == $this->query_vars['type']) {
$where .= ' AND comment_type IN ("pingback", "trackback")';
} elseif (!empty($this->query_vars['type'])) {
$where .= $wpdb->prepare(' AND comment_type = %s', $this->query_vars['type']);
}
if ('' !== $this->query_vars['parent']) {
$where .= $wpdb->prepare(' AND comment_parent = %d', $this->query_vars['parent']);
}
if (is_array($this->query_vars['user_id'])) {
$where .= ' AND user_id IN (' . implode(',', array_map('absint', $this->query_vars['user_id'])) . ')';
} elseif ('' !== $this->query_vars['user_id']) {
$where .= $wpdb->prepare(' AND user_id = %d', $this->query_vars['user_id']);
}
if ('' !== $this->query_vars['search']) {
$where .= $this->get_search_sql($this->query_vars['search'], array('comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content'));
}
$plucked = wp_array_slice_assoc($this->query_vars, array('post_author', 'post_name', 'post_parent', 'post_status', 'post_type'));
$post_fields = array_filter($plucked);
if (!empty($post_fields)) {
$join = "JOIN {$wpdb->posts} ON {$wpdb->posts}.ID = {$wpdb->comments}.comment_post_ID";
foreach ($post_fields as $field_name => $field_value) {
$where .= $wpdb->prepare(" AND {$wpdb->posts}.{$field_name} = %s", $field_value);
}
}
if (!empty($this->meta_query->queries)) {
$clauses = $this->meta_query->get_sql('comment', $wpdb->comments, 'comment_ID', $this);
$join .= $clauses['join'];
$where .= $clauses['where'];
$groupby = "{$wpdb->comments}.comment_ID";
}
$date_query = $this->query_vars['date_query'];
if (!empty($date_query) && is_array($date_query)) {
$date_query_object = new WP_Date_Query($date_query, 'comment_date');
$where .= $date_query_object->get_sql();
}
$pieces = array('fields', 'join', 'where', 'orderby', 'order', 'limits', 'groupby');
/**
* Filter the comment query clauses.
*
* @since 3.1.0
*
* @param array $pieces A compacted array of comment query clauses.
* @param WP_Comment_Query &$this Current instance of WP_Comment_Query, passed by reference.
*/
$clauses = apply_filters_ref_array('comments_clauses', array(compact($pieces), &$this));
$fields = isset($clauses['fields']) ? $clauses['fields'] : '';
$join = isset($clauses['join']) ? $clauses['join'] : '';
$where = isset($clauses['where']) ? $clauses['where'] : '';
$orderby = isset($clauses['orderby']) ? $clauses['orderby'] : '';
$order = isset($clauses['order']) ? $clauses['order'] : '';
$limits = isset($clauses['limits']) ? $clauses['limits'] : '';
$groupby = isset($clauses['groupby']) ? $clauses['groupby'] : '';
if ($groupby) {
$groupby = 'GROUP BY ' . $groupby;
}
$query = "SELECT {$fields} FROM {$wpdb->comments} {$join} WHERE {$where} {$groupby} ORDER BY {$orderby} {$order} {$limits}";
if ($this->query_vars['count']) {
return $wpdb->get_var($query);
}
if ('ids' == $this->query_vars['fields']) {
$this->comments = $wpdb->get_col($query);
return array_map('intval', $this->comments);
}
$results = $wpdb->get_results($query);
/**
* Filter the comment query results.
*
* @since 3.1.0
*
* @param array $results An array of comments.
* @param WP_Comment_Query &$this Current instance of WP_Comment_Query, passed by reference.
*/
$comments = apply_filters_ref_array('the_comments', array($results, &$this));
wp_cache_add($cache_key, $comments, 'comment');
return $comments;
}
示例14: get_posts
//.........这里部分代码省略.........
}
if (strlen($q['m']) > 11) {
$where .= " AND MINUTE({$this->db->posts}.post_date)=" . substr($q['m'], 10, 2);
}
if (strlen($q['m']) > 13) {
$where .= " AND SECOND({$this->db->posts}.post_date)=" . substr($q['m'], 12, 2);
}
}
// Handle the other individual date parameters
$date_parameters = array();
if ('' !== $q['hour']) {
$date_parameters['hour'] = $q['hour'];
}
if ('' !== $q['minute']) {
$date_parameters['minute'] = $q['minute'];
}
if ('' !== $q['second']) {
$date_parameters['second'] = $q['second'];
}
if ($q['year']) {
$date_parameters['year'] = $q['year'];
}
if ($q['monthnum']) {
$date_parameters['monthnum'] = $q['monthnum'];
}
if ($q['w']) {
$date_parameters['week'] = $q['w'];
}
if ($q['day']) {
$date_parameters['day'] = $q['day'];
}
if ($date_parameters) {
$date_query = new WP_Date_Query(array($date_parameters));
$where .= $date_query->get_sql();
}
unset($date_parameters, $date_query);
// Handle complex date queries
if (!empty($q['date_query'])) {
$this->date_query = new WP_Date_Query($q['date_query']);
$where .= $this->date_query->get_sql();
}
// If we've got a post_type AND it's not "any" post_type.
if (!empty($q['post_type']) && 'any' != $q['post_type']) {
foreach ((array) $q['post_type'] as $_post_type) {
$ptype_obj = get_post_type_object($_post_type);
if (!$ptype_obj || !$ptype_obj->query_var || empty($q[$ptype_obj->query_var])) {
continue;
}
if (!$ptype_obj->hierarchical) {
// Non-hierarchical post types can directly use 'name'.
$q['name'] = $q[$ptype_obj->query_var];
} else {
// Hierarchical post types will operate through 'pagename'.
$q['pagename'] = $q[$ptype_obj->query_var];
$q['name'] = '';
}
// Only one request for a slug is possible, this is why name & pagename are overwritten above.
break;
}
//end foreach
unset($ptype_obj);
}
if ('' !== $q['title']) {
$where .= $this->db->prepare(" AND {$this->db->posts}.post_title = %s", stripslashes($q['title']));
}
// Parameters related to 'post_name'.
示例15: prepare_items
public function prepare_items()
{
global $wpdb;
$page = $this->get_pagenum();
$offset = ($page - 1) * $this->per_page;
$checkout_fields_sql = "\n\t\t\tSELECT id, unique_name FROM " . WPSC_TABLE_CHECKOUT_FORMS . " WHERE unique_name IN ('billingfirstname', 'billinglastname', 'billingemail') AND active='1' AND checkout_set='0'\n\t\t";
$checkout_fields = $wpdb->get_results($checkout_fields_sql);
$joins = array();
$where = array('1 = 1');
if (isset($_REQUEST['post'])) {
$posts = array_map('absint', $_REQUEST['post']);
$where[] = ' and (p.id IN (' . implode(', ', $posts) . '))';
}
$i = 1;
$selects = array('p.id', 'p.totalprice AS amount', 'p.processed AS status', 'p.track_id', 'p.date');
$selects[] = '
(
SELECT SUM(quantity) FROM ' . WPSC_TABLE_CART_CONTENTS . ' AS c
WHERE c.purchaseid = p.id
) AS item_count';
$search_terms = empty($_REQUEST['s']) ? array() : explode(' ', $_REQUEST['s']);
$search_sql = array();
foreach ($checkout_fields as $field) {
$table_as = 's' . $i;
$select_as = str_replace('billing', '', $field->unique_name);
$selects[] = $table_as . '.value AS ' . $select_as;
$joins[] = $wpdb->prepare("LEFT OUTER JOIN " . WPSC_TABLE_SUBMITTED_FORM_DATA . " AS {$table_as} ON {$table_as}.log_id = p.id AND {$table_as}.form_id = %d", $field->id);
// build search term queries for first name, last name, email
foreach ($search_terms as $term) {
if (version_compare($GLOBALS['wp_version'], '4.0', '>=')) {
$escaped_term = esc_sql(like_escape($term));
} else {
$escaped_term = esc_sql($wpdb->esc_like($term));
}
if (!array_key_exists($term, $search_sql)) {
$search_sql[$term] = array();
}
$search_sql[$term][] = $table_as . ".value LIKE '%" . $escaped_term . "%'";
}
$i++;
}
// combine query phrases into a single query string
foreach ($search_terms as $term) {
$search_sql[$term][] = "p.track_id = '" . esc_sql($term) . "'";
if (is_numeric($term)) {
$search_sql[$term][] = 'p.id = ' . esc_sql($term);
}
$search_sql[$term] = '(' . implode(' OR ', $search_sql[$term]) . ')';
}
$search_sql = implode(' AND ', array_values($search_sql));
if ($search_sql) {
$where[] = " AND ({$search_sql})";
}
// filter by status
if (!empty($_REQUEST['status']) && $_REQUEST['status'] != 'all') {
$this->status = absint($_REQUEST['status']);
$where[] = ' AND (processed = ' . $this->status . ')';
}
$this->where_no_filter = implode(' ', $where);
// filter by month
if (!empty($_REQUEST['m'])) {
// so we can tell WP_Date_Query we're legit
add_filter('date_query_valid_columns', array($this, 'set_date_column_to_date'));
if (strlen($_REQUEST['m']) < 4) {
$query_args = $this->assemble_predefined_periods_query($_REQUEST['m']);
} else {
$query_args = array('year' => (int) substr($_REQUEST['m'], 0, 4), 'monthnum' => (int) substr($_REQUEST['m'], -2));
}
$date_query = new WP_Date_Query($query_args, $column = '__date__');
/* this is a subtle hack since the FROM_UNIXTIME doesn't survive WP_Date_Query
* so we use __date__ as a proxy
*/
$where[] = str_replace('__date__', 'FROM_UNIXTIME(p.date)', $date_query->get_sql());
}
$selects = apply_filters('wpsc_manage_purchase_logs_selects', implode(', ', $selects));
$this->joins = apply_filters('wpsc_manage_purchase_logs_joins', implode(' ', $joins));
$this->where = apply_filters('wpsc_manage_purchase_logs_where', implode(' ', $where));
$limit = $this->per_page !== 0 ? "LIMIT {$offset}, {$this->per_page}" : '';
$orderby = empty($_REQUEST['orderby']) ? 'p.id' : 'p.' . $_REQUEST['orderby'];
$order = empty($_REQUEST['order']) ? 'DESC' : $_REQUEST['order'];
$orderby = esc_sql(apply_filters('wpsc_manage_purchase_logs_orderby', $orderby));
$order = esc_sql($order);
$purchase_log_sql = apply_filters('wpsc_manage_purchase_logs_sql', "\n\t\t\tSELECT SQL_CALC_FOUND_ROWS {$selects}\n\t\t\tFROM " . WPSC_TABLE_PURCHASE_LOGS . " AS p\n\t\t\t{$this->joins}\n\t\t\tWHERE {$this->where}\n\t\t\tORDER BY {$orderby} {$order}\n\t\t\t{$limit}\n\t\t");
$this->items = apply_filters('wpsc_manage_purchase_logs_items', $wpdb->get_results($purchase_log_sql));
if ($this->per_page) {
$total_items = $wpdb->get_var("SELECT FOUND_ROWS()");
$this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $this->per_page));
}
$total_where = apply_filters('wpsc_manage_purchase_logs_total_where', $this->where);
if ($this->status == 'all') {
$total_where .= ' AND p.processed IN (3, 4, 5) ';
}
$total_sql = "\n\t\t\tSELECT SUM(totalprice)\n\t\t\tFROM " . WPSC_TABLE_PURCHASE_LOGS . " AS p\n\t\t\t{$this->joins}\n\t\t\tWHERE {$total_where}\n\t\t";
$this->total_amount = $wpdb->get_var($total_sql);
}