Switch language

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




get_metadata [ WordPress Function ]

get_metadata ( $meta_type, $object_id, $meta_key = '', $single = 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 Optional. Metadata key. If not specified, retrieve all metadata for the specified object.
  • (bool) $single Optional, default is false. If true, return only the first value of the specified meta_key. This parameter has no effect if meta_key is not specified.
Returns:
  • (string|array) Single metadata value, or array of values
Defined at:



Retrieve metadata for the specified object.

Source


<?php
function get_metadata($meta_type$object_id$meta_key ''$single false) {
    if ( !
$meta_type )
        return 
false;

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

    
$check apply_filters"get_{$meta_type}_metadata"null$object_id$meta_key$single );
    if ( 
null !== $check ) {
        if ( 
$single && is_array$check ) )
            return 
$check[0];
        else
            return 
$check;
    }

    
$meta_cache wp_cache_get($object_id$meta_type '_meta');

    if ( !
$meta_cache ) {
        
$meta_cache update_meta_cache$meta_type, array( $object_id ) );
        
$meta_cache $meta_cache[$object_id];
    }

    if ( !
$meta_key )
        return 
$meta_cache;

    if ( isset(
$meta_cache[$meta_key]) ) {
        if ( 
$single )
            return 
maybe_unserialize$meta_cache[$meta_key][0] );
        else
            return 
array_map('maybe_unserialize'$meta_cache[$meta_key]);
    }

    if (
$single)
        return 
'';
    else
        return array();
}
?>

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