mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-22 08:11:52 +01:00
Fix meta_key and meta_value queries in get_pages(). Props filosofo. fixes #6773 for trunk
git-svn-id: http://svn.automattic.com/wordpress/trunk@7746 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
fbe04fbf90
commit
17deb910aa
@ -1954,11 +1954,21 @@ function &get_pages($args = '') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = "SELECT * FROM $wpdb->posts " ;
|
$join = '';
|
||||||
$query .= ( empty( $meta_key ) ? "" : ", $wpdb->postmeta " ) ;
|
$where = "$exclusions $inclusions ";
|
||||||
$query .= " WHERE (post_type = 'page' AND post_status = 'publish') $exclusions $inclusions " ;
|
if ( ! empty( $meta_key ) || ! empty( $meta_value ) ) {
|
||||||
// expected_slashed ($meta_key, $meta_value) -- also, it looks funky
|
$join = " LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )";
|
||||||
$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) ) ;
|
|
||||||
|
// meta_key and met_value might be slashed
|
||||||
|
$meta_key = stripslashes($meta_key);
|
||||||
|
$meta_value = stripslashes($meta_value);
|
||||||
|
if ( ! empty( $meta_key ) )
|
||||||
|
$where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key);
|
||||||
|
if ( ! empty( $meta_value ) )
|
||||||
|
$where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_value = %s", $meta_value);
|
||||||
|
|
||||||
|
}
|
||||||
|
$query = "SELECT * FROM $wpdb->posts $join WHERE (post_type = 'page' AND post_status = 'publish') $where ";
|
||||||
$query .= $author_query;
|
$query .= $author_query;
|
||||||
$query .= " ORDER BY " . $sort_column . " " . $sort_order ;
|
$query .= " ORDER BY " . $sort_column . " " . $sort_order ;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user