Example #1
0
 /**
  *
  * get post meta data
  *
  * @param string  $key
  * @param string  $field_name
  * @param boolean $remove_first if array have only one element and if should be removed set to true
  *
  * @return mixed array, string or false if not found
  */
 public static function getPostMeta($key, $field_name, $post_id = null, $remove_first = true)
 {
     $key = self::getKeyName($key);
     $post_meta = \get_post_meta($post_id, $key, true);
     if ($post_meta && RecursiveArray::searchKey($field_name, $post_meta)) {
         $matches = RecursiveArray::searchRecursive($post_meta, $field_name);
         if (\count($matches) == 1 && \is_array($matches) && $remove_first) {
             return $matches[0];
         }
         return $matches;
     } else {
         return false;
     }
 }
Example #2
0
 /**
  * Get single meta box by name
  *
  * @param int    $post_id
  * @param string $control_name valid meta box name
  * @param bool   $remove_first remove first element
  *
  * @return array|boolean
  *
  * @access   public
  */
 public function get($post_id, $control_name, $remove_first = true)
 {
     $post_meta = get_post_meta($post_id, $this->getId(), true);
     if ($post_meta && RecursiveArray::searchKey($control_name, $post_meta)) {
         $meta_boxes = RecursiveArray::searchRecursive($post_meta, $control_name);
         if (\count($meta_boxes) == 1 && \is_array($meta_boxes) && $remove_first) {
             return $meta_boxes[0];
         }
         if (is_array($meta_boxes)) {
             $meta_boxes = RecursiveArray::removeEmpty($meta_boxes);
         }
         return $meta_boxes;
     } else {
         return false;
     }
 }