* @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
* @param int $object_id ID of the object metadata is for
* @param string $meta_key Metadata key
- * @param string $meta_value Metadata value
+ * @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
* @param bool $unique Optional, default is false. Whether the specified metadata key should be
* unique for the object. If true, and the object already has a value for the specified
* metadata key, no change will be made
* @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
* @param int $object_id ID of the object metadata is for
* @param string $meta_key Metadata key
- * @param string $meta_value Metadata value
- * @param string $prev_value Optional. If specified, only update existing metadata entries with
+ * @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
+ * @param mixed $prev_value Optional. If specified, only update existing metadata entries with
* the specified value. Otherwise, update all entries.
* @return bool True on successful update, false on failure.
*/
if ( 'post' == $meta_type )
do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
- $wpdb->update( $table, $data, $where );
+ $result = $wpdb->update( $table, $data, $where );
+ if ( ! $result )
+ return false;
wp_cache_delete($object_id, $meta_type . '_meta');
* @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
* @param int $object_id ID of the object metadata is for
* @param string $meta_key Metadata key
- * @param string $meta_value Optional. Metadata value. If specified, only delete metadata entries
+ * @param mixed $meta_value Optional. Metadata value. Must be serializable if non-scalar. If specified, only delete metadata entries
* with this value. Otherwise, delete all entries with the specified meta_key.
* @param bool $delete_all Optional, default is false. If true, delete matching metadata entries
* for all objects, ignoring the specified object_id. Otherwise, only delete matching
do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
// Run the update query, all fields in $data are %s, $where is a %d.
- $result = (bool) $wpdb->update( $table, $data, $where, '%s', '%d' );
+ $result = $wpdb->update( $table, $data, $where, '%s', '%d' );
+ if ( ! $result )
+ return false;
// Clear the caches.
wp_cache_delete($object_id, $meta_type . '_meta');
if ( 'post' == $meta_type )
do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
- return $result;
+ return true;
}
// And if the meta was not found.
* - 'key' string The meta key
* - 'value' string|array The meta value
* - 'compare' (optional) string How to compare the key to the value.
- * Possible values: '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'.
+ * Possible values: '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN',
+ * 'BETWEEN', 'NOT BETWEEN', 'REGEXP', 'NOT REGEXP', 'RLIKE'.
* Default: '='
* - 'type' string (optional) The type of the value.
* Possible values: 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED'.
$this->__construct( $meta_query );
}
+ /**
+ * Given a meta type, return the appropriate alias if applicable
+ *
+ * @since 3.7.0
+ *
+ * @param string $type MySQL type to cast meta_value
+ * @return string MySQL type
+ */
+ function get_cast_for_type( $type = '' ) {
+ if ( empty( $type ) )
+ return 'CHAR';
+
+ $meta_type = strtoupper( $type );
+
+ if ( ! in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED', 'NUMERIC' ) ) )
+ return 'CHAR';
+
+ if ( 'NUMERIC' == $meta_type )
+ $meta_type = 'SIGNED';
+
+ return $meta_type;
+ }
+
/**
* Generates SQL clauses to be appended to a main query.
*
$key_only_queries[$k] = $q;
unset( $this->queries[$k] );
}
- }
-
+ }
+
// Split out the meta_key only queries (we can only do this for OR)
if ( 'OR' == $this->relation ) {
foreach ( $this->queries as $k => $q ) {
foreach ( $queries as $k => $q ) {
$meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : '';
- $meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR';
-
- if ( 'NUMERIC' == $meta_type )
- $meta_type = 'SIGNED';
- elseif ( ! in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED' ) ) )
- $meta_type = 'CHAR';
+ $meta_type = $this->get_cast_for_type( isset( $q['type'] ) ? $q['type'] : '' );
$meta_value = isset( $q['value'] ) ? $q['value'] : null;
'LIKE', 'NOT LIKE',
'IN', 'NOT IN',
'BETWEEN', 'NOT BETWEEN',
- 'NOT EXISTS'
+ 'NOT EXISTS',
+ 'REGEXP', 'NOT REGEXP', 'RLIKE'
) ) )
$meta_compare = '=';