Ticket #2563: postmeta_val_test_get_posts_and_get_pages.diff
| File postmeta_val_test_get_posts_and_get_pages.diff, 4.2 KB (added by , 21 years ago) |
|---|
-
wp-includes/functions.php
1454 1454 parse_str($args, $r); 1455 1455 1456 1456 $defaults = array('numberposts' => 5, 'offset' => 0, 'category' => '', 1457 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '' );1457 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' =>''); 1458 1458 $r = array_merge($defaults, $r); 1459 1459 extract($r); 1460 1460 1461 1461 $inclusions = ''; 1462 1462 if ( !empty($include) ) { 1463 $offset = 0; //ignore offset, category, and exclude params if using include1463 $offset = 0; //ignore offset, category, exclude, meta_key, and meta_value params if using include 1464 1464 $category = ''; 1465 1465 $exclude = ''; 1466 $meta_key = ''; 1467 $meta_value = ''; 1466 1468 $incposts = preg_split('/[\s,]+/',$include); 1467 1469 $numberposts = count($incposts); // only the number of posts included 1468 1470 if ( count($incposts) ) { … … 1492 1494 if (!empty($exclusions)) 1493 1495 $exclusions .= ')'; 1494 1496 1495 $posts = $wpdb->get_results( 1496 "SELECT DISTINCT * FROM $wpdb->posts " . 1497 ( empty( $category ) ? "" : ", $wpdb->post2cat " ) . 1498 " WHERE (post_type = 'post' AND post_status = 'publish') $exclusions $inclusions " . 1499 ( empty( $category ) ? "" : "AND $wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $category. " " ) . 1500 " GROUP BY $wpdb->posts.ID ORDER BY " . $orderby . " " . $order . " LIMIT " . $offset . ',' . $numberposts ); 1497 $query ="SELECT DISTINCT * FROM $wpdb->posts " ; 1498 $query .= ( empty( $category ) ? "" : ", $wpdb->post2cat " ) ; 1499 $query .= ( empty( $meta_key ) ? "" : ", $wpdb->postmeta " ) ; 1500 $query .= " WHERE (post_type = 'post' AND post_status = 'publish') $exclusions $inclusions " ; 1501 $query .= ( empty( $category ) ? "" : "AND ($wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $category. ") " ) ; 1502 $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' )" ) ; 1503 $query .= " GROUP BY $wpdb->posts.ID ORDER BY " . $orderby . " " . $order . " LIMIT " . $offset . ',' . $numberposts ; 1501 1504 1505 $posts = $wpdb->get_results($query); 1506 1502 1507 update_post_caches($posts); 1503 1508 1504 1509 return $posts; -
wp-includes/template-functions-post.php
306 306 parse_str($args, $r); 307 307 308 308 $defaults = array('child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title', 309 'hierarchical' => 1, $exclude => '', $include =>'');310 $r =array_merge($defaults, $r);309 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'meta_key' => '', 'meta_value' =>''); 310 array_merge($defaults, $r); 311 311 extract($r); 312 312 313 313 $inclusions = ''; 314 314 if ( !empty($include) ) { 315 $child_of = 0; //ignore child_of and exclude params if using include315 $child_of = 0; //ignore child_of, exclude, meta_key, and meta_value params if using include 316 316 $exclude = ''; 317 $meta_key = ''; 318 $meta_value = ''; 317 319 $incpages = preg_split('/[\s,]+/',$include); 318 320 if ( count($incpages) ) { 319 321 foreach ( $incpages as $incpage ) { … … 342 344 if (!empty($exclusions)) 343 345 $exclusions .= ')'; 344 346 345 $ pages = $wpdb->get_results("SELECT * " .346 "FROM $wpdb->posts " .347 "WHERE post_type = 'page' AND post_status = 'publish' " .348 "$exclusions $inclusions" .349 "ORDER BY " . $sort_column . " " . $sort_order);347 $query ="SELECT * FROM $wpdb->posts " ; 348 $query .= ( empty( $meta_key ) ? "" : ", $wpdb->postmeta " ) ; 349 $query .= " WHERE (post_type = 'page' AND post_status = 'publish') $exclusions $inclusions " ; 350 $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' )" ) ; 351 $query .= " ORDER BY " . $sort_column . " " . $sort_order ; 350 352 353 $pages = $wpdb->get_results($query); 354 351 355 if ( empty($pages) ) 352 356 return array(); 353 357
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)