Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taricco/572933c6d381fd0125c582ac333a8186 to your computer and use it in GitHub Desktop.
Save taricco/572933c6d381fd0125c582ac333a8186 to your computer and use it in GitHub Desktop.
/*** Set ACF field default as Post ID for the modal_id field for the video and match CPTs
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
function wsv_post_id_default_for_modal_id($post_id) {
// Check if we're saving a 'video' or 'match' post type
$post_type = get_post_type($post_id);
if ($post_type == 'video' || $post_type == 'match') {
// Retrieve the current value of the 'modal_id' field
$current_value = get_field('modal_id', $post_id);
// If the 'modal_id' field is empty, set it to the post ID
if (empty($current_value)) {
update_field('modal_id', $post_id, $post_id);
}
}
}
add_action('acf/save_post', 'wsv_post_id_default_for_modal_id', 20);
/*** Set ACF field default as Post ID for the modal_id field for the video CPT
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
function wsv_post_id_default_for_modal_id($post_id) {
// Check if we're saving a 'video' post type
if (get_post_type($post_id) == 'video') {
// Retrieve the current value of the 'modal_id' field
$current_value = get_field('modal_id', $post_id);
// If the 'modal_id' field is empty, set it to the post ID
if (empty($current_value)) {
update_field('modal_id', $post_id, $post_id);
}
}
}
add_action('acf/save_post', 'wsv_post_id_default_for_modal_id', 20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment