Choosing post relation via custom code

  • Posted 1 month ago

Hi,

Im trying endless options but now im lost on how to proceed.

I’m creating a custom QR-based input system that adds a new post of type shot-log.
The post type and relation are managed by Voxel. QR scan bypass login and ads log for specific weapon.

Using the REST API, I can successfully create the post and set standard fields like number and date.
However, the relation field (log-relation-weapon) doesn’t attach the selected weapon.

In the database, the following meta keys exist:

log-relation-weapon _voxel_field_log-relation-weapon _relations _relations_cache _field_data

I’ve tried updating both log-relation-weapon and _voxel_field_log-relation-weapon, but the relation doesn’t show up in the backend.

Could you please confirm:

What is the correct internal structure or function to set a Voxel relation field programmatically (outside the form builder)? Does it require updating _relations or using a Voxel helper like \Voxel\Dynamic_Tags\Field_Data::update_relations()? Is there a way to bypass the “author-only” relation restriction when posting via custom code?

Example:

update_post_meta($post_id, ‘log-relation-weapon’, [$weapon_id]); update_post_meta($post_id, ‘_voxel_field_log-relation-weapon’, [$weapon_id]);

This saves the meta, but doesn’t attach the relation visually in the backend.

Thanks a lot — everything else (rounds and date) saves correctly, so we just need the proper Voxel call or format for relations.

Best regards,

Martin