WordPressを読む 27-5 /blog/wp-includes/query.php 5
2014/12/11
目次
/blog/wp-includes/query.php 5
WP_Query::parse_orderby()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | /** * If the passed orderby value is allowed, convert the alias to a * properly-prefixed orderby value. * * @since 4.0.0 * @access protected * * @global wpdb $wpdb WordPress database access abstraction object. * * @param string $orderby Alias for the field to order by. * @return string|bool Table-prefixed value to used in the ORDER clause. False otherwise. */ protected function parse_orderby( $orderby ) { global $wpdb; // Used to filter values. $allowed_keys = array( 'post_name', 'post_author', 'post_date', 'post_title', 'post_modified', 'post_parent', 'post_type', 'name', 'author', 'date', 'title', 'modified', 'parent', 'type', 'ID', 'menu_order', 'comment_count', 'rand', ); $meta_key = $this->get( 'meta_key' ); if ( ! empty( $meta_key ) ) { $allowed_keys[] = $meta_key; $allowed_keys[] = 'meta_value'; $allowed_keys[] = 'meta_value_num'; } if ( ! in_array( $orderby, $allowed_keys ) ) { return false; } switch ( $orderby ) { case 'post_name': case 'post_author': case 'post_date': case 'post_title': case 'post_modified': case 'post_parent': case 'post_type': case 'ID': case 'menu_order': case 'comment_count': $orderby = "$wpdb->posts.{$orderby}"; break; case 'rand': $orderby = 'RAND()'; break; case $meta_key: case 'meta_value': $type = $this->get( 'meta_type' ); if ( ! empty( $type ) ) { $meta_type = $this->meta_query->get_cast_for_type( $type ); $orderby = "CAST($wpdb->postmeta.meta_value AS {$meta_type})"; } else { $orderby = "$wpdb->postmeta.meta_value"; } break; case 'meta_value_num': $orderby = "$wpdb->postmeta.meta_value+0"; break; default: $orderby = "$wpdb->posts.post_" . $orderby; break; } return $orderby; } |
WP_Query::parse_order()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | /** * Parse an 'order' query variable and cast it to ASC or DESC as necessary. * * @since 4.0.0 * @access protected * * @param string $order The 'order' query variable. * @return string The sanitized 'order' query variable. */ protected function parse_order( $order ) { if ( ! is_string( $order ) || empty( $order ) ) { return 'DESC'; } if ( 'ASC' === strtoupper( $order ) ) { return 'ASC'; } else { return 'DESC'; } } |
WP_Query::set_404()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | /** * Sets the 404 property and saves whether query is feed. * * @since 2.0.0 * @access public */ public function set_404() { $is_feed = $this->is_feed; $this->init_query_flags(); $this->is_404 = true; $this->is_feed = $is_feed; } |
WP_Query::get()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | /** * Retrieve query variable. * * @since 1.5.0 * @access public * * @param string $query_var Query variable key. * @param mixed $default Value to return if the query variable is not set. Default ''. * @return mixed */ public function get( $query_var, $default = '' ) { if ( isset( $this->query_vars[ $query_var ] ) ) { return $this->query_vars[ $query_var ]; } return $default; } |
WP_Query::set()
1 2 3 4 5 6 7 8 9 10 11 12 | /** * Set query variable. * * @since 1.5.0 * @access public * * @param string $query_var Query variable key. * @param mixed $value Query variable value. */ public function set($query_var, $value) { $this->query_vars[$query_var] = $value; } |