I am trying to wrap my head around how to use save_post and update_field to combine a field from a post, as well as an option field, into a new field within said post. I don’t know if I need to create the new field first and somehow hide it from the options form, or if I can have it display after save but make it non-editable.. or if acf just makes it in the background without the need for me to make it first (sorry if that doesn’t make sense).
Here’s what I’m trying to do:
In an acf options page, a user will enter their affiliate id: affiliate_id
When creating a post, they will enter a product number: product_id
When the post is saved I want a new field named “link”, within that post, to automatically combine those values so that the following is saved for the new “link” field:
http://www.productsite.com/(product_id)/?ref=(affiliate_id)
Here’s my guess so far as to how this might be done, but it’s really a wild guess trying to string these things together without much php knowledge:
function my_acf_save_post( $post_id ) {
$affid = (int) get_field('affid');
$prod = (int) get_field('affiliate_id', 'option');
$link = update_field( "http://www.productsite.com/" . $prod . "/?ref=" . $affid . ""; );
add_action('acf/save_post', 'my_acf_save_post', 15);