yit_get_post_meta

Retrieve the value of a metabox.

Description

yit_get_post_meta( (int) $id, (string) $meta ); 

This function retrieve the value of a metabox attached to a post. It return either a single value or an array.

Parameters (2)

0. $id (int)
Post ID.
1. $meta (string)
The meta key to retrieve.

Usage

  1. if ( !function_exists( 'yit_get_post_meta' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'yith-woocommerce-compare/plugin-fw/yit-functions.php'; 
  3.  
  4. // Post ID. 
  5. $id = -1; 
  6.  
  7. // The meta key to retrieve. 
  8. $meta = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = yit_get_post_meta($id, $meta); 
  12.  

Defined (1)

The function is defined in the following location(s).

/plugin-fw/yit-functions.php  
  1. function yit_get_post_meta ( $id, $meta ) { 
  2. if ( ! strpos ( $meta, '[' ) ) { 
  3. return get_post_meta ( $id, $meta, true ); 
  4.  
  5. $sub_meta = explode ( '[', $meta ); 
  6.  
  7. $meta = get_post_meta ( $id, $meta, true ); 
  8. for ( $i = 0; $i < count ( $sub_meta ); $i ++ ) { 
  9. $meta = $meta[ rtrim ( $sub_meta[ $i ], ']' ) ]; 
  10.  
  11. return $meta;