Created
February 17, 2024 00:54
-
-
Save taricco/572933c6d381fd0125c582ac333a8186 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** 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