Skip to content

Instantly share code, notes, and snippets.

@rinatkhaziev
Created February 15, 2012 03:07
Show Gist options
  • Save rinatkhaziev/1832823 to your computer and use it in GitHub Desktop.
Save rinatkhaziev/1832823 to your computer and use it in GitHub Desktop.
Easily get post meta values for Custom Metaboxes and Fields plugin
<?php
/**
* Easily get post meta value for Custom Metaboxes and Fields plugin
*
* @see https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress
*
* @param string $key to retrieve
* @param bool $echo if true then echo value
* @param string $sanitize_callback sanitize value with this callback
* @param string $cmb_prefix prefix of post meta
*/
function rk_cmb_get_meta ( $key = '', $echo = false, $sanitize_callback = '', $cmb_post = false, $cmb_prefix = false ) {
global $prefix, $post;
$prefix = $cmb_prefix ? $cmb_prefix : $prefix;
$cmb_post = is_object( $cmb_post ) ? $cmb_post : $post;
$value = get_post_meta( intval( $cmb_post->ID ), $prefix . $key, true );
if( $sanitize_callback && is_callable( $sanitize_callback ) )
$value = call_user_func( $sanitize_callback, $value );
if( $echo )
echo $value;
else
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment