Created
November 4, 2019 22:17
-
-
Save MogulChris/5a0bc20d1823edd205323f3bcb4883b2 to your computer and use it in GitHub Desktop.
Default values for ACF flexible content fields
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
<?php | |
//Set a default layout to appear in a Flexible Content Field for certain post types (eg products) | |
//We just set a default value for our desired field. This is an array of arrays. | |
//Each inner array requires at minimum an element called 'acf_fc_layout'. You may also set other field default values here (use field keys, not names). | |
function mytheme_set_default_layout($value, $post_id, $field){ | |
if(get_post_type($post_id) == 'product' && empty($value)){ | |
$value = array( | |
array( 'acf_fc_layout' => 'LAYOUT_NAME' /*, 'field_5dc07c52a036c' => 'field default value' */ ) | |
); | |
} | |
return $value; | |
} | |
add_filter('acf/load_value/name=FIELD_NAME', 'mytheme_set_default_layout',10,3); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment