llms_update_user_postmeta( int $user_id, int $post_id, string $meta_key, mixed $meta_value, bool $unique = true )
Update user postmeta data.
Parameters Parameters
- $user_id
-
(int) (Required) WP User ID.
- $post_id
-
(int) (Required) WP Post ID.
- $meta_key
-
(string) (Required) Meta key.
- $meta_value
-
(mixed) (Required) Meta value (don't serialize serializable values).
- $unique
-
(bool) (Optional) If true, updates existing value (if it exists). If false, will add a new record (allowing multiple records with the same key to exist). Deafult true.
Default value: true
Return Return
(bool)
Source Source
File: includes/functions/llms.functions.user.postmeta.php
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | function llms_update_user_postmeta( $user_id , $post_id , $meta_key , $meta_value , $unique = true ) { $item = false; // if unique is true, make an update to the existing item (if it exists). if ( $unique ) { // locate the item. $existing = _llms_query_user_postmeta( $user_id , $post_id , $meta_key ); if ( $existing ) { // load it and make sure it exists. $item = new LLMS_User_Postmeta( $existing [0]->meta_id, false ); if ( ! $item ->exists() ) { $item = false; } } } if ( ! $item ) { $item = new LLMS_User_Postmeta(); } // setup the data we want to store. $updated_date = llms_current_time( 'mysql' ); $meta_value = maybe_serialize( $meta_value ); $item ->setup( compact( 'user_id' , 'post_id' , 'meta_key' , 'meta_value' , 'updated_date' ) ); return $item ->save(); } |
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.21.0 | Introduced. |