WordPress.org

Make WordPress Core

Changeset 7746


Ignore:
Timestamp:
04/18/2008 10:29:43 PM (13 years ago)
Author:
ryan
Message:

Fix meta_key and meta_value queries in get_pages(). Props filosofo. fixes #6773 for trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r7743 r7746  
    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 ;
Note: See TracChangeset for help on using the changeset viewer.