/** * Get post meta * * @param string $key Meta key. Required. * @param int|null $post_id Post ID. null for current post. Optional * @param array $args Array of arguments. Optional. * * @return mixed */ function rwmb_meta($key, $args = array(), $post_id = null) { $post_id = empty($post_id) ? get_the_ID() : $post_id; $args = wp_parse_args($args, array('type' => 'text')); // Set 'multiple' for fields based on 'type' $args['multiple'] = in_array($args['type'], array('checkbox_list', 'file', 'image', 'plupload_image', 'thickbox_image')); $meta = get_post_meta($post_id, $key, !$args['multiple']); // Get uploaded files info if ('file' == $args['type']) { if (is_array($meta) && !empty($meta)) { $files = array(); foreach ($meta as $id) { $files[$id] = rwmb_file_info($id); } $meta = $files; } } elseif (in_array($args['type'], array('image', 'plupload_image', 'thickbox_image'))) { if (is_array($meta) && !empty($meta)) { global $wpdb; $meta = implode(',', $meta); // Re-arrange images with 'menu_order' $meta = $wpdb->get_col("\n\t\t\t\tSELECT ID FROM {$wpdb->posts}\n\t\t\t\tWHERE post_type = 'attachment'\n\t\t\t\tAND ID in ({$meta})\n\t\t\t\tORDER BY menu_order ASC\n\t\t\t"); $images = array(); foreach ($meta as $id) { $images[$id] = rwmb_image_info($id, $args); } $meta = $images; } } elseif ('taxonomy' == $args['type']) { $meta = emtpy($args['taxonomy']) ? array() : wp_get_post_terms($post_id, $args['taxonomy']); } return $meta; }
/** * Get post meta * * @param string $key Meta key. Required. * @param int|null $post_id Post ID. null for current post. Optional * @param array $args Array of arguments. Optional. * * @return mixed */ function rwmb_meta($key, $args = array(), $post_id = null) { $post_id = empty($post_id) ? get_the_ID() : $post_id; $args = wp_parse_args($args, array('type' => 'text')); // Set 'multiple' for fields based on 'type' $args['multiple'] = in_array($args['type'], array('checkbox_list', 'file', 'file_advanced', 'image', 'image_advanced', 'plupload_image', 'thickbox_image')); $meta = get_post_meta($post_id, $key, !$args['multiple']); // Get uploaded files info if (in_array($args['type'], array('file', 'file_advanced'))) { if (is_array($meta) && !empty($meta)) { $files = array(); foreach ($meta as $id) { $files[$id] = rwmb_file_info($id); } $meta = $files; } } elseif (in_array($args['type'], array('image', 'plupload_image', 'thickbox_image', 'image_advanced'))) { if (is_array($meta) && !empty($meta)) { $images = array(); foreach ($meta as $id) { $images[$id] = rwmb_image_info($id, $args); } $meta = $images; } } elseif ('taxonomy_advanced' == $args['type']) { if (!empty($args['taxonomy'])) { $term_ids = array_map('intval', array_filter(explode(',', $meta . ','))); $meta = array(); foreach ($term_ids as $term_id) { $meta[] = get_term($term_id, $args['taxonomy']); } } else { $meta = array(); } } elseif ('taxonomy' == $args['type']) { $meta = empty($args['taxonomy']) ? array() : wp_get_post_terms($post_id, $args['taxonomy']); } elseif ('map' == $args['type']) { $meta = rwmb_meta_map($key, $args, $post_id); } return apply_filters(__FUNCTION__, $meta, $key, $args, $post_id); }
function wpsight_get_file_info($id) { if (empty($id)) { $id = get_the_ID(); } $info = rwmb_file_info($id); return apply_filters('wpsight_get_file_info', $info, $id); }