| | |
| | | return $this->getWpDefault($item, $name); |
| | | } |
| | | |
| | | // Taxonomy fields are stored in term_relationships, not meta |
| | | $config = $item->getFieldConfig($name); |
| | | if ($config |
| | | && ( |
| | | ($config['type'] ?? '') === 'taxonomy' |
| | | || (($config['type']??'') === 'selector' && ($config['subtype']??'') === 'taxonomy') |
| | | ) && !isset($config['taxonomy_type'])) { |
| | | return $this->getTaxonomyField($item, $config); |
| | | } |
| | | |
| | | $metaKey = BASE . $name; |
| | | |
| | | return match ($item->objectType) { |
| | |
| | | |
| | | $defaults = Item::WP_DEFAULTS[$item->objectType] ?? []; |
| | | $wpFields = array_intersect($defaults, $fieldNames); |
| | | $metaFields = array_diff($fieldNames, $wpFields); |
| | | |
| | | // Separate taxonomy fields from regular meta fields |
| | | $taxonomyFields = []; |
| | | $metaFields = []; |
| | | foreach (array_diff($fieldNames, $wpFields) as $name) { |
| | | $config = $item->getFieldConfig($name); |
| | | if ($config |
| | | && ( |
| | | ($config['type'] ?? '') === 'taxonomy' |
| | | || (($config['type']??'') === 'selector' && ($config['subtype']??'') === 'taxonomy') |
| | | ) && !isset($config['taxonomy_type'])) { |
| | | $taxonomyFields[$name] = $config; |
| | | } else { |
| | | $metaFields[] = $name; |
| | | } |
| | | } |
| | | |
| | | $values = []; |
| | | |
| | | // Get meta fields in bulk query |
| | | if (!empty($metaFields)) { |
| | | $values = $this->bulkGetMeta($item, $metaFields); |
| | | } |
| | | |
| | | // Get WP default fields |
| | | foreach ($wpFields as $name) { |
| | | $values[$name] = $this->getWpDefault($item, $name); |
| | | } |
| | | |
| | | foreach ($taxonomyFields as $name => $config) { |
| | | $values[$name] = $this->getTaxonomyField($item, $config); |
| | | } |
| | | |
| | | return $values; |
| | | } |
| | | |
| | | protected function getTaxonomyField(Item $item, array $config): string |
| | | { |
| | | $taxonomy = jvbCheckBase($config['taxonomy']); |
| | | error_log('Getting taxonomy field for taxonomy: '.print_r($taxonomy, true)); |
| | | $terms = wp_get_object_terms($item->id, $taxonomy, ['fields' => 'ids']); |
| | | |
| | | if (is_wp_error($terms) || empty($terms)) { |
| | | return ''; |
| | | } |
| | | |
| | | return implode(',', $terms); |
| | | } |
| | | |
| | | /** |
| | | * Save a single field |
| | | */ |