Ticket #5358: 5358.2.diff
File 5358.2.diff, 5.8 KB (added by , 11 years ago) |
---|
-
wp-includes/query.php
58 58 } 59 59 60 60 /** 61 * Retrieve the currently-queried objects. Wrapper for $wp_query->get_queried_objects() 62 * 63 * @uses WP_Query::get_queried_objects 64 * 65 * @since 3.7.0 66 * @access public 67 * 68 * @return object|null 69 */ 70 function get_queried_objects() { 71 global $wp_query; 72 return $wp_query->get_queried_objects(); 73 } 74 75 /** 76 * Retrieve IDs of the current queried objects. Wrapper for $wp_query->get_queried_object_ids() 77 * 78 * @uses WP_Query::get_queried_object_ids() 79 * 80 * @since 3.7.0 81 * @access public 82 * 83 * @return int 84 */ 85 function get_queried_object_ids() { 86 global $wp_query; 87 return $wp_query->get_queried_object_ids(); 88 } 89 90 /** 61 91 * Set query variable. 62 92 * 63 93 * @see WP_Query::set() … … 896 926 var $queried_object_id; 897 927 898 928 /** 929 * Holds the data for the objects that are queried. 930 * 931 * @since 3.7.0 932 * @access public 933 * @var array 934 */ 935 var $queried_objects; 936 937 /** 938 * The IDs of the queried objects. 939 * 940 * @since 3.7.0 941 * @access public 942 * @var array 943 */ 944 var $queried_object_ids; 945 946 /** 899 947 * Get post database query. 900 948 * 901 949 * @since 2.0.1 … … 3027 3075 * @return object 3028 3076 */ 3029 3077 function get_queried_object() { 3030 if ( isset($this->queried_object) ) 3031 return $this->queried_object; 3078 $this->get_queried_objects(); 3079 return $this->queried_object; 3080 } 3032 3081 3033 $this->queried_object = null; 3034 $this->queried_object_id = 0; 3082 /** 3083 * Retrieve ID of the current queried object. 3084 * 3085 * @since 1.5.0 3086 * @access public 3087 * 3088 * @return int 3089 */ 3090 function get_queried_object_id() { 3091 $this->get_queried_objects(); 3092 return $this->queried_object_id; 3093 } 3035 3094 3095 /** 3096 * Retrieve queried objects. 3097 * 3098 * If queried objects is not set, then the queried object will be set from 3099 * the categories, tags, taxonomies, posts page, single post, page, or author 3100 * query variable. After it is set up, it will be returned. 3101 * 3102 * @since 3.7.0 3103 * @access public 3104 * 3105 * @return array 3106 */ 3107 public function get_queried_objects() { 3108 if ( isset( $this->queried_objects ) ) 3109 return $this->queried_objects; 3110 3111 $this->queried_objects = array(); 3112 $this->queried_object_ids = array(); 3113 3036 3114 if ( $this->is_category || $this->is_tag || $this->is_tax ) { 3037 3115 $tax_query_in_and = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'NOT IN' ), 'NOT' ); 3038 3116 3117 $terms = array(); 3039 3118 $query = reset( $tax_query_in_and ); 3040 3119 3041 if ( 'term_id' == $query['field'] ) 3042 $term = get_term( reset( $query['terms'] ), $query['taxonomy'] ); 3043 elseif ( $query['terms'] ) 3044 $term = get_term_by( $query['field'], reset( $query['terms'] ), $query['taxonomy'] ); 3120 if ( $query['terms'] ) { 3121 foreach ( $query['terms'] as $term ) { 3122 $term = get_term_by( $query['field'], $term, $query['taxonomy'] ); 3123 if ( $term && ! is_wp_error( $term ) ) { 3124 $terms[] = $term; 3125 } 3126 } 3127 } 3045 3128 3046 if ( ! empty( $term ) && ! is_wp_error( $term ) ) { 3047 $this->queried_object = $term; 3048 $this->queried_object_id = (int) $term->term_id; 3129 if ( ! empty( $terms ) ) { 3130 if ( $this->is_category ) { 3131 foreach ( $terms as &$category ) { 3132 _make_cat_compat( $category ); 3133 } 3134 unset( $category ); 3135 } 3049 3136 3050 if ( $this->is_category )3051 _make_cat_compat( $this->queried_object);3137 $this->queried_objects = $terms; 3138 $this->queried_object_ids = wp_list_pluck( $this->queried_objects, 'term_id' ); 3052 3139 } 3053 3140 } elseif ( $this->is_post_type_archive ) { 3054 $this->queried_object = get_post_type_object( $this->get('post_type') ); 3141 $post_types = (array) $this->get( 'post_type' ); 3142 foreach ( $post_types as $post_type ) { 3143 $this->queried_objects[] = get_post_type_object( $post_type ); 3144 } 3055 3145 } elseif ( $this->is_posts_page ) { 3056 $page_for_posts = get_option( 'page_for_posts');3057 $this->queried_object = get_post( $page_for_posts );3058 $this->queried_object_id = (int) $this->queried_object->ID;3059 } elseif ( $this->is_singular && ! is_null($this->post) ) {3060 $this->queried_object = $this->post;3061 $this->queried_object_id = (int) $this->post->ID;3146 $page_for_posts = get_option( 'page_for_posts' ); 3147 $this->queried_objects[] = get_post( $page_for_posts ); 3148 $this->queried_object_ids = wp_list_pluck( $this->queried_objects, 'ID' ); 3149 } elseif ( $this->is_singular && ! is_null( $this->post ) ) { 3150 $this->queried_objects[] = $this->post; 3151 $this->queried_object_ids = wp_list_pluck( $this->queried_objects, 'ID' ); 3062 3152 } elseif ( $this->is_author ) { 3063 $this->queried_object_id = (int) $this->get('author'); 3064 $this->queried_object = get_userdata( $this->queried_object_id ); 3153 $this->queried_object_ids = array_map( 'absint', (array) $this->get( 'author' ) ); 3154 foreach ( $this->queried_object_ids as $user_id ) { 3155 $this->queried_objects[] = get_userdata( $user_id ); 3156 } 3065 3157 } 3066 3158 3067 return $this->queried_object; 3159 // back-compat for get_queried_object and get_queried_object_id 3160 $this->queried_object = ( ! empty( $this->queried_objects ) ) ? reset( $this->queried_objects ) : null; 3161 $this->queried_object_id = ( ! empty( $this->queried_object_ids ) ) ? reset( $this->queried_object_ids ) : 0; 3162 3163 return $this->queried_objects; 3068 3164 } 3069 3165 3070 3166 /** 3071 * Retrieve ID of the current queried object.3167 * Retrieve IDs of the current queried objects. 3072 3168 * 3073 * @since 1.5.03169 * @since 3.7.0 3074 3170 * @access public 3075 3171 * 3076 * @return int3172 * @return array 3077 3173 */ 3078 function get_queried_object_id() { 3079 $this->get_queried_object(); 3080 3081 if ( isset($this->queried_object_id) ) { 3082 return $this->queried_object_id; 3083 } 3084 3085 return 0; 3174 public function get_queried_object_ids() { 3175 $this->get_queried_objects(); 3176 return $this->queried_object_ids; 3086 3177 } 3087 3178 3088 3179 /**