Quantcast
Channel: WordPress Snippet
Viewing all articles
Browse latest Browse all 129

メタデータがあるかどうか確認してから処理

$
0
0

// Check and get a term meta
 
if ( metadata_exists( 'term', $term_id, '_meta_key' ) ) {
    $meta_value = get_term_meta( $term_id, '_meta_key', true );
}
 
// Check and get a post meta
 
if ( metadata_exists( 'post', $post_id, '_meta_key' ) ) {
    $meta_value = get_post_meta( $post_id, '_meta_key', true );
}
 
// Check and get a user meta
 
if ( metadata_exists( 'user', $user_id, '_meta_key' ) ) {
    $meta_value = get_user_meta( $user_id, '_meta_key', true );
}


Viewing all articles
Browse latest Browse all 129

Trending Articles