本文整理汇总了PHP中WP_Date_Query类的典型用法代码示例。如果您正苦于以下问题:PHP WP_Date_Query类的具体用法?PHP WP_Date_Query怎么用?PHP WP_Date_Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WP_Date_Query类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor.
*
* @param array $date_query
* @param string $column
*
* @see WP_Date_Query::__construct()
*/
public function __construct($date_query, $column = '')
{
if (!empty($column)) {
$this->column = $column;
add_filter('date_query_valid_columns', array($this, 'register_date_column'));
}
parent::__construct($date_query, $column);
}
开发者ID:mawilliamson,项目名称:wordpress,代码行数:16,代码来源:class-bp-date-query.php
示例2: 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;
}
开发者ID:sebgrey,项目名称:xbookings,代码行数:29,代码来源:Booking.php
示例3: prepare_query
//.........这里部分代码省略.........
} else {
// Non-integer key means this the key is the field and the value is ASC/DESC.
$_orderby = $_key;
$_order = $_value;
}
$parsed = $this->parse_orderby($_orderby);
if (!$parsed) {
continue;
}
$orderby_array[] = $parsed . ' ' . $this->parse_order($_order);
}
// If no valid clauses were found, order by user_login.
if (empty($orderby_array)) {
$orderby_array[] = "user_login {$order}";
}
$this->query_orderby = 'ORDER BY ' . implode(', ', $orderby_array);
// limit
if ($qv['number']) {
if ($qv['offset']) {
$this->query_limit = $wpdb->prepare("OFFSET %d ROWS FETCH NEXT %d ROWS ONLY", $qv['offset'], $qv['number']);
} else {
$this->query_limit = $wpdb->prepare("OFFSET 0 ROWS FETCH NEXT %d ROWS ONLY", $qv['number']);
}
}
$search = '';
if (isset($qv['search'])) {
$search = trim($qv['search']);
}
if ($search) {
$leading_wild = ltrim($search, '*') != $search;
$trailing_wild = rtrim($search, '*') != $search;
if ($leading_wild && $trailing_wild) {
$wild = 'both';
} elseif ($leading_wild) {
$wild = 'leading';
} elseif ($trailing_wild) {
$wild = 'trailing';
} else {
$wild = false;
}
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);
}
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));
}
开发者ID:remonlam,项目名称:projectnami,代码行数:101,代码来源:user.php
示例4: test_build_time_query_minute_second
public function test_build_time_query_minute_second()
{
$q = new WP_Date_Query(array());
$found = $q->build_time_query('post_date', '=', null, 15, 35);
// $compare value is floating point - use regex to account for
// varying precision on different PHP installations
$this->assertRegExp("/DATE_FORMAT\\( post_date, '0\\.%i%s' \\) = 0\\.15350*/", $found);
}
开发者ID:Benrajalu,项目名称:philRaj,代码行数:8,代码来源:query.php
示例5: 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;
}
开发者ID:sunyang3721,项目名称:wp-for-sae,代码行数:101,代码来源:comment.php
示例6: get_commissions
/**
* Get Commissions
*
* @param array $q
*
* @return array
* @author Andrea Grillo <[email protected]>
* @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'";
//.........这里部分代码省略.........
开发者ID:kanhaiyasharma,项目名称:Bestswiss,代码行数:101,代码来源:class.yith-commissions.php
示例7: wp_get_archives
public static function wp_get_archives($args = array())
{
global $wpdb, $wp_rewrite;
$r = wp_parse_args($args, array('type' => 'monthly', 'post_type' => 'post', 'order' => 'DESC', 'date_query' => null));
$r['post_type'] = sanitize_key($r['post_type']);
if (!post_type_exists($r['post_type'])) {
return array();
}
if ('' == $r['type']) {
$r['type'] = 'monthly';
}
$order = strtoupper($r['order']);
if ($order !== 'ASC') {
$order = 'DESC';
}
$where = " WHERE {$wpdb->posts}.post_type = '" . $r['post_type'] . "' AND {$wpdb->posts}.post_status = 'publish'";
if (!empty($r['date_query'])) {
$date_query = new WP_Date_Query($r['date_query']);
$where .= $date_query->get_sql();
}
$where = apply_filters('getarchives_where', $where, $args);
$where = apply_filters('ry_getarchives_where', $where, $args);
$join = '';
$join = apply_filters('getarchives_join', $join, $args);
$join = apply_filters('ry_getarchives_join', $join, $args);
$last_changed = wp_cache_get('last_changed', 'posts');
if (!$last_changed) {
$last_changed = microtime();
wp_cache_set('last_changed', $last_changed, 'posts');
}
$list = array();
if ('monthly' == $r['type']) {
$query = "SELECT YEAR({$wpdb->posts}.post_date) AS `year`, MONTH({$wpdb->posts}.post_date) AS `month` FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR({$wpdb->posts}.post_date), MONTH({$wpdb->posts}.post_date) ORDER BY {$wpdb->posts}.post_date {$order} {$limit}";
$key = md5($query);
$key = "RY_CP_wp_get_archives:{$key}:{$last_changed}";
if (!($results = wp_cache_get($key, 'posts'))) {
$results = $wpdb->get_results($query);
wp_cache_set($key, $results, 'posts');
}
if ($results) {
$permalink_type = $wp_rewrite->get_month_permastruct();
$permalink_type = empty($permalink_type);
foreach ((array) $results as $result) {
$url = get_month_link($result->year, $result->month);
if ($r['post_type'] != 'post') {
if ($permalink_type) {
$url .= '&post_type=' . $r['post_type'];
} else {
$url = str_replace('/date/', '/date/' . $r['post_type'] . '/', $url);
}
}
$list[] = array('year' => $result->year, 'month' => $result->month, 'day' => 0, 'url' => $url);
}
}
} elseif ('yearly' == $r['type']) {
$query = "SELECT YEAR({$wpdb->posts}.post_date) AS `year` FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR({$wpdb->posts}.post_date) ORDER BY {$wpdb->posts}.post_date {$order} {$limit}";
$key = md5($query);
$key = "RY_CP_wp_get_archives:{$key}:{$last_changed}";
if (!($results = wp_cache_get($key, 'posts'))) {
$results = $wpdb->get_results($query);
wp_cache_set($key, $results, 'posts');
}
if ($results) {
$permalink_type = $wp_rewrite->get_year_permastruct();
$permalink_type = empty($permalink_type);
foreach ((array) $results as $result) {
$url = get_year_link($result->year);
if ($r['post_type'] != 'post') {
if ($permalink_type) {
$url .= '&post_type=' . $r['post_type'];
} else {
$url = str_replace('/date/', '/date/' . $r['post_type'] . '/', $url);
}
}
$list[] = array('year' => $result->year, 'month' => 0, 'day' => 0, 'url' => $url);
}
}
} elseif ('daily' == $r['type']) {
$query = "SELECT YEAR({$wpdb->posts}.post_date) AS `year`, MONTH({$wpdb->posts}.post_date) AS `month`, DAYOFMONTH({$wpdb->posts}.post_date) AS `day` FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR({$wpdb->posts}.post_date), MONTH({$wpdb->posts}.post_date), DAYOFMONTH({$wpdb->posts}.post_date) ORDER BY {$wpdb->posts}.post_date {$order} {$limit}";
$key = md5($query);
$key = "RY_CP_wp_get_archives:{$key}:{$last_changed}";
if (!($results = wp_cache_get($key, 'posts'))) {
$results = $wpdb->get_results($query);
wp_cache_set($key, $results, 'posts');
}
if ($results) {
$archive_day_date_format = 'Y/m/d';
if (!(bool) $r['over_date']) {
$archive_day_date_format = get_option('date_format');
}
$permalink_type = $wp_rewrite->get_day_permastruct();
$permalink_type = empty($permalink_type);
foreach ((array) $results as $result) {
$url = get_day_link($result->year, $result->month, $result->day);
if ($r['post_type'] != 'post') {
if ($permalink_type) {
$url .= '&post_type=' . $r['post_type'];
} else {
$url = str_replace('/date/', '/date/' . $r['post_type'] . '/', $url);
}
//.........这里部分代码省略.........
开发者ID:RicherYang,项目名称:ry-custom-pagination,代码行数:101,代码来源:class.ry-cp.php
示例8: get_posts
//.........这里部分代码省略.........
$where .= " AND HOUR({$this->db->posts}.post_date)=" . substr($q['m'], 8, 2);
}
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']));
}
开发者ID:inpsyde,项目名称:wordpress-dev,代码行数:67,代码来源:class-wp-query.php
示例9: get_posts
//.........这里部分代码省略.........
$where .= " AND HOUR({$wpdb->posts}.post_date)=" . substr($q['m'], 8, 2);
}
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'] . "'";
开发者ID:Nancers,项目名称:Snancy-Website-Files,代码行数:67,代码来源:query.php
示例10: date_where
/**
* 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;
}
开发者ID:acutedeveloper,项目名称:havering-intranet-development,代码行数:19,代码来源:class.swp-query.php
示例11: 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);
}
开发者ID:socialray,项目名称:surfied-2-0,代码行数:40,代码来源:bp-follow-classes.php
示例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));
}
开发者ID:trinoamez,项目名称:WordpressPlatzi,代码行数:101,代码来源:user.php
示例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;
}
开发者ID:justatechnology,项目名称:Security,代码行数:101,代码来源:comment.php
示例14: do_action_ref_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) {
开发者ID:ryan2407,项目名称:Vision,代码行数:67,代码来源:networkquery.php
示例15: 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_
|
请发表评论