kolejna próba
Zdjęcia oferty
// =====================================================
// OD / FIRMY: półautomat tworzenia profilu firmy (draft)
// Trigger: przypisanie termu w taksonomii od_firma do posta
// Działa dla formularza i ręcznej edycji (brak wyścigu z save_post)
// =====================================================
add_action(’set_object_terms’, function ($object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids) {
// interesuje nas tylko firma
if ($taxonomy !== 'od_firma’) return;
$post_id = (int) $object_id;
if ($post_id slug) || empty($term->name)) return;
$term_slug = sanitize_title((string) $term->slug);
$term_id = (int) $term->term_id;
$term_name = (string) $term->name;
if ($term_slug === ” || $term_id 'od_company’,
'post_status’ => [’publish’, 'draft’, 'pending’, 'private’],
'posts_per_page’ => 1,
'fields’ => 'ids’,
'meta_query’ => [[
'key’ => 'od_company_term_slug’,
'value’ => $term_slug,
'compare’ => '=’,
]],
]);
if (!empty($existing)) {
return; // profil już jest (nawet jako draft)
}
// utwórz szkic profilu firmy
$profile_id = wp_insert_post([
'post_type’ => 'od_company’,
'post_status’ => 'draft’,
'post_title’ => $term_name,
'post_content’ => ”,
], true);
if (is_wp_error($profile_id) || !$profile_id) return;
// zapisz powiązanie z terminem
update_post_meta((int)$profile_id, 'od_company_term_slug’, $term_slug);
update_post_meta((int)$profile_id, 'od_company_term_id’, $term_id);
}, 20, 6);
Parametry
- Gatunek drewna: Grab
- Sortyment: Kantówka
- Długość: 3