Programatically updating association field values
From the docs I’m not able to setup the {key} and {value} for the carbon_set_{container_type} ( {id}, {key}, {value} ); function. When I currently output an entry out off the association field array it looks like this (case for associated term):
array(
'value' => term:{taxonomy}:{id}
'type' => {term}
'subtype' => {taxonomy}
'id' => {id}
)
Is it possible to update association fields? How would it look like? Thanks!
P.S. I need this to sync associations fields between the associated terms. In version 1.6 it was a unique entry with an array and building and updating was easy.
Version
- Carbon Fields: 2.2
- WordPress: 4.9+
- PHP: 7+
You could do something like this:
carbon_set_post_meta(
ID_OF_THE_POST,
'seminar',
array(
array(
'value' => 'post:seminar:' . ID_OF_THE_ASSOCIATION,
'id' => ID_OF_THE_ASSOCIATION,
'type' => 'post',
'subtype' => 'seminar'
)
)
);
In this case seminar is the post-type.
Thanks @AnagramEngineering, this is what we finally did, forgot to update our research here. It works also with terms:
'value' => 'term:' . ID_TERM_TAXONOMY . ':' . ID_ASSOCIATED_TERM,
and users:
'value' => 'user:user:' . ID_ASSOCIATED_USER,
setting
'type', 'subtype' and 'id' accordingly.
What if the association is within a complex field. How would it look like then?