本文整理汇总了PHP中WP_Query::parse_orderby方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Query::parse_orderby方法的具体用法?PHP WP_Query::parse_orderby怎么用?PHP WP_Query::parse_orderby使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Query
的用法示例。
在下文中一共展示了WP_Query::parse_orderby方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse_orderby
/**
* If the passed orderby value is allowed, convert the alias to a
* properly-prefixed orderby value.
*
* @access protected
*
* @param string $orderby Alias for the field to order by.
* @return string|false Field to use in the sort clause. False otherwise.
*/
protected function parse_orderby($orderby)
{
// Meta values get special treatment
$meta_keys = array();
$meta_clauses = $this->meta_query->queries;
if (!empty($meta_clauses)) {
if ('meta_value' == $orderby) {
return $this->parse_orderby_for_meta(reset($meta_clauses));
} elseif ('meta_value_num' == $orderby) {
return $this->parse_orderby_for_meta(reset($meta_clauses), 'double');
} elseif (array_key_exists($orderby, $meta_clauses)) {
return $this->parse_orderby_for_meta($meta_clauses[$orderby]);
}
}
if ('rand' == $orderby) {
// @todo: implement `random_score`
return false;
}
$field = parent::parse_orderby($orderby);
// We don't actually want the mysql column here, so we'll remove it
$field = preg_replace('/^.*\\./', '', $field);
if ('ID' == $field) {
return $this->es_map('post_id');
} elseif (!preg_match('/[^a-z_]/i', $field)) {
// Return it if the field only contains letters and underscores
return $this->es_map($field);
}
return false;
}