Changeset 3854 for trunk/wp-includes/post.php
- Timestamp:
- 06/08/2006 02:22:16 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/post.php
r3851 r3854 145 145 } 146 146 147 function get_posts($args) { 148 global $wpdb; 149 150 if ( is_array($args) ) 151 $r = &$args; 152 else 153 parse_str($args, $r); 154 155 $defaults = array('numberposts' => 5, 'offset' => 0, 'category' => '', 156 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' =>''); 157 $r = array_merge($defaults, $r); 158 extract($r); 159 160 $inclusions = ''; 161 if ( !empty($include) ) { 162 $offset = 0; //ignore offset, category, exclude, meta_key, and meta_value params if using include 163 $category = ''; 164 $exclude = ''; 165 $meta_key = ''; 166 $meta_value = ''; 167 $incposts = preg_split('/[\s,]+/',$include); 168 $numberposts = count($incposts); // only the number of posts included 169 if ( count($incposts) ) { 170 foreach ( $incposts as $incpost ) { 171 if (empty($inclusions)) 172 $inclusions = ' AND ( ID = ' . intval($incpost) . ' '; 173 else 174 $inclusions .= ' OR ID = ' . intval($incpost) . ' '; 175 } 176 } 177 } 178 if (!empty($inclusions)) 179 $inclusions .= ')'; 180 181 $exclusions = ''; 182 if ( !empty($exclude) ) { 183 $exposts = preg_split('/[\s,]+/',$exclude); 184 if ( count($exposts) ) { 185 foreach ( $exposts as $expost ) { 186 if (empty($exclusions)) 187 $exclusions = ' AND ( ID <> ' . intval($expost) . ' '; 188 else 189 $exclusions .= ' AND ID <> ' . intval($expost) . ' '; 190 } 191 } 192 } 193 if (!empty($exclusions)) 194 $exclusions .= ')'; 195 196 $query ="SELECT DISTINCT * FROM $wpdb->posts " ; 197 $query .= ( empty( $category ) ? "" : ", $wpdb->post2cat " ) ; 198 $query .= ( empty( $meta_key ) ? "" : ", $wpdb->postmeta " ) ; 199 $query .= " WHERE (post_type = 'post' AND post_status = 'publish') $exclusions $inclusions " ; 200 $query .= ( empty( $category ) ? "" : "AND ($wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $category. ") " ) ; 201 $query .= ( empty( $meta_key ) | empty($meta_value) ? "" : " AND ($wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '$meta_key' AND $wpdb->postmeta.meta_value = '$meta_value' )" ) ; 202 $query .= " GROUP BY $wpdb->posts.ID ORDER BY " . $orderby . " " . $order . " LIMIT " . $offset . ',' . $numberposts ; 203 204 $posts = $wpdb->get_results($query); 205 206 update_post_caches($posts); 207 208 return $posts; 209 } 147 210 148 211 // … … 931 994 } } 932 995 return $result; 996 } 997 998 function get_page_uri($page_id) { 999 $page = get_page($page_id); 1000 $uri = urldecode($page->post_name); 1001 1002 // A page cannot be it's own parent. 1003 if ( $page->post_parent == $page->ID ) 1004 return $uri; 1005 1006 while ($page->post_parent != 0) { 1007 $page = get_page($page->post_parent); 1008 $uri = urldecode($page->post_name) . "/" . $uri; 1009 } 1010 1011 return $uri; 933 1012 } 934 1013
Note: See TracChangeset
for help on using the changeset viewer.