Skip to content

Instantly share code, notes, and snippets.

@jrgd
Last active March 27, 2018 20:39
Show Gist options
  • Save jrgd/984a1e3914fa37a083ec184722e2d684 to your computer and use it in GitHub Desktop.
Save jrgd/984a1e3914fa37a083ec184722e2d684 to your computer and use it in GitHub Desktop.
Insert ACF Post Meta
// Simple ACF Field insertion based on explanation here:
// https://support.advancedcustomfields.com/forums/topic/acf-repeater-filed-in-add_post_meta/
// and the awesome Get Field Key https://gist.github.com/mcguffin/81509c36a4a28d9c682e
function insert_acf_post_meta($key, $value_to_insert, $id) {
$field_name = $key;
$field_name__ = "_".$field_name;
$field_key = acf_get_field_key( $field_name, $id );
add_post_meta($id, $field_name, $value_to_insert, true);
add_post_meta($id, $field_name__, $field_key, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment