Home › Forums › Front-end Issues › Post Object Field – Set selected value programatically › Reply To: Post Object Field – Set selected value programatically
You can use the update_field function to put the post ID in outside of anything related to the ACF form:
<?php update_field($selector, $value, $post_id); ?>
$selector would be the field ID: field_57319b21314aa
Depending on the rest of the setup I think would depend on how would be most effective to get that information into the form, whether it’s populated before or after you submit. It could be possible to use the WP pre_get_posts() hook or the acf/save_post hook, grab the post ID and then update the field with it in the relevant place.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
The most recent ACF Chat Friday featured a live demo of how to register CPTs directly in the plugin, one of our most requested features. Check out the summary below for a replay of the demo, and don’t forget to register for the next session! https://t.co/k2KQ3WWBAz— Advanced Custom Fields (@wp_acf) March 9, 2023
© 2023 Advanced Custom Fields.