Forked from taricco/Set ACF field default as Post ID for the modal_id field.php
Created
April 22, 2025 07:53
-
-
Save infocities/1f8be4da7e7958bbaa3e5bdbce6aac90 to your computer and use it in GitHub Desktop.
This file contains hidden or 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