Last active
March 8, 2024 16:40
-
-
Save zackpyle/79b095a9f36640e432b3d5d29b561770 to your computer and use it in GitHub Desktop.
Set a different default #ACF value based on the post type
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
<?php | |
add_filter('acf/load_field/key=YOUR_FIELD_KEY_HERE', function ($field) { | |
if (get_post_type() == 'post') { | |
$field['default_value'] = 'YOUR_DEFAULT_VALUE_HERE'; | |
} | |
return $field; | |
}); | |
// If the field type is a checkbox, then give it an array (even if it is a single value) | |
add_filter('acf/load_field/key=YOUR_FIELD_KEY_HERE', function ($field) { | |
if (get_post_type() == 'post') { | |
$field['default_value'] = ['choice1', 'choice3']; | |
} | |
return $field; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment