/** * 非複数許可フィールドのメタデータを取得 * * @param WP_Post|WP_User|object $object * @param Smart_Custom_Fields_Field_Base $Field * @param int $index * @return string or null */ public function get_single_data_field_value($object, $Field, $index) { $Meta = new Smart_Custom_Fields_Meta($object); $field_name = $Field->get('name'); if (is_null($index)) { return SCF::get_default_value($Field, true); } if ($Meta->is_saved()) { $value = $Meta->get($field_name); if (isset($value[$index])) { return $value[$index]; } return ''; } return SCF::get_default_value($Field, true); }
/** * Getting the meta data of the field * * @param WP_Post|WP_User|WP_Term $object * @param array $field * @param bool $is_repeatable Whether the group that this field belongs is repetition * @return mixed $post_meta */ protected static function get_value_by_field($object, $Field, $is_repeatable) { $field_name = $Field->get('name'); if (!$field_name) { return; } $Meta = new Smart_Custom_Fields_Meta($object); // In the case of multi-value items in the loop $field_type = $Field->get_attribute('type'); $repeat_multiple_data = self::get_repeat_multiple_data($object); if (is_array($repeat_multiple_data) && isset($repeat_multiple_data[$field_name])) { if ($Meta->is_saved()) { $_meta = $Meta->get($field_name); } else { $_meta = self::get_default_value($Field); } $start = 0; foreach ($repeat_multiple_data[$field_name] as $repeat_multiple_key => $repeat_multiple_value) { if ($repeat_multiple_value === 0) { $value = array(); } else { $value = array_slice($_meta, $start, $repeat_multiple_value); $start += $repeat_multiple_value; } $value = apply_filters(SCF_Config::PREFIX . 'validate-get-value', $value, $field_type); $meta[$repeat_multiple_key] = $value; } } else { $single = true; if ($Field->get_attribute('allow-multiple-data') || $is_repeatable) { $single = false; } if ($Meta->is_saved()) { $meta = $Meta->get($field_name, $single); } else { $meta = self::get_default_value($Field, $single); } $meta = apply_filters(SCF_Config::PREFIX . 'validate-get-value', $meta, $field_type); } return $meta; }