Hi!
I am writing a custom function in PHP in the functions.php file (using the standard WordPress API) to add a listing to the website based on the received data.
I am able to create a listing, assign categories, name, description, and meta fields (attributes like number and text).
I want to assign a value to an attribute of type “list”.
I tried to do it similarly to categories, but it didn’t work:
wp_set_post_terms($post_id, array($tip_nedvigimosti_id), 'hp_listing_tipneruhomosti');
I also couldn’t access the values of the list-type attribute directly, so I manually assigned the ID values based on their labels:
$tip_nedvigimosti_id = get_or_create_tip_nedvigimosti($row['tip-nedvigimosti']);
function get_or_create_tip_nedvigimosti($tip_nedvigimosti) {
$terms_map = array(
'1+1' => 100,
'1+kk' => 99,
'2+1' => 102,
'2+kk' => 101,
'3+1' => 104,
'3+kk' => 103,
'4+1' => 106,
'4+kk' => 105,
'5+1' => 108,
'5+kk' => 107,
'6 і більше' => 109,
'Атиповий' => 110,
'Кімната' => 98
);
if (array_key_exists($tip_nedvigimosti, $terms_map)) {
return $terms_map[$tip_nedvigimosti];
} else {
return false;
}
}
Can you please advise how to assign a value to a list-type attribute?
It would be helpful to get access to the values of this attribute.
Is it possible to use a function from the theme itself? If so, could you provide a link to the syntax?
Thanks