WordPress.org

Make WordPress Core

Ticket #6773: get_pages.diff

File get_pages.diff, 1.5 KB (added by filosofo, 10 years ago)
  • wp-includes/post.php

     
    19541954                }
    19551955        }
    19561956
    1957         $query = "SELECT * FROM $wpdb->posts " ;
    1958         $query .= ( empty( $meta_key ) ? "" : ", $wpdb->postmeta " ) ;
    1959         $query .= " WHERE (post_type = 'page' AND post_status = 'publish') $exclusions $inclusions " ;
    1960         // expected_slashed ($meta_key, $meta_value) -- also, it looks funky
    1961         $query .= ( empty( $meta_key ) | empty($meta_value)  ? "" : $wpdb->prepare(" AND ($wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = %s AND $wpdb->postmeta.meta_value = %s )", $meta_key, $meta_value) ) ;
     1957        $join = '';
     1958        $where = "$exclusions $inclusions ";
     1959        if ( ! empty( $meta_key ) || ! empty( $meta_value ) ) {
     1960                $join = " LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )";
     1961               
     1962                // meta_key and met_value might be slashed
     1963                $meta_key = stripslashes($meta_key);
     1964                $meta_value = stripslashes($meta_value);
     1965                if ( ! empty( $meta_key ) )
     1966                        $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key);
     1967                if ( ! empty( $meta_value ) )
     1968                        $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_value = %s", $meta_value);
     1969
     1970        }
     1971        $query = "SELECT * FROM $wpdb->posts $join WHERE (post_type = 'page' AND post_status = 'publish') $where ";
    19621972        $query .= $author_query;
    19631973        $query .= " ORDER BY " . $sort_column . " " . $sort_order ;
    19641974