Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




add_metadata [ WordPress Function ]

add_metadata ( $meta_type, $object_id, $meta_key, $meta_value, $unique = false )
Parameters:
  • (string) $meta_type Type of object metadata is for (e.g., comment, post, or user)
  • (int) $object_id ID of the object metadata is for
  • (string) $meta_key Metadata key
  • (string) $meta_value Metadata value
  • (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
Uses:
Returns:
  • (bool) The meta ID on successful update, false on failure.
Defined at:



Add metadata for the specified object.

Source


<?php
function add_metadata($meta_type$object_id$meta_key$meta_value$unique false) {
    if ( !
$meta_type || !$meta_key )
        return 
false;

    if ( !
$object_id absint($object_id) )
        return 
false;

    if ( ! 
$table _get_meta_table($meta_type) )
        return 
false;

    global 
$wpdb;

    
$column esc_sql($meta_type '_id');

    
// expected_slashed ($meta_key)
    
$meta_key stripslashes($meta_key);
    
$meta_value stripslashes_deep($meta_value);
    
$meta_value sanitize_meta$meta_key$meta_value$meta_type );

    
$check apply_filters"add_{$meta_type}_metadata"null$object_id$meta_key$meta_value$unique );
    if ( 
null !== $check )
        return 
$check;

    if ( 
$unique && $wpdb->get_var$wpdb->prepare(
        
"SELECT COUNT(*) FROM $table WHERE meta_key = %s AND $column = %d",
        
$meta_key$object_id ) ) )
        return 
false;

    
$_meta_value $meta_value;
    
$meta_value maybe_serialize$meta_value );

    
do_action"add_{$meta_type}_meta"$object_id$meta_key$_meta_value );

    
$result $wpdb->insert$table, array(
        
$column => $object_id,
        
'meta_key' => $meta_key,
        
'meta_value' => $meta_value
    
) );

    if ( ! 
$result )
        return 
false;

    
$mid = (int) $wpdb->insert_id;

    
wp_cache_delete($object_id$meta_type '_meta');

    
do_action"added_{$meta_type}_meta"$mid$object_id$meta_key$_meta_value );

    return 
$mid;
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

Gebruikersdiscussies [ wordpress.org ]

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics