I don’t see a difference of concept in your solution, but glad you got your problem solved
Come on guys, when are you going to allow us to enter the api key the normal way ? Filters are cool, but I don’t want to search for this page every time I need a google maps field.
Well, here’s how to do it in 5.5.13:
add_filter('acf/load_value/key= key_58c7ee3a37aee', 'default_value_ key_58c7ee3a37aee', 10, 3);
function default_value_ key_58c7ee3a37aee($value, $post_id, $field) {
if ($value === false) {
$value = array(
array(
'field_58984ddb5b8cc' => 'My title',
'field_58985045abac0' => 'My content',
),
array(
'field_58984ddb5b8cc' => 'Another title for a content-less row',
),
);
}
return $value;
}
Same syntax, only difference is you put it inside the appropriate filter. I prefer to use this code in the same file that I have exported the field in question.
Bloody hell, my solution is no longer working in 5.5.13 … I don’t understand why they would remove this awesome functionality … featured or not, it served great.
A clean approach here tested in version 5.5.7, you can just set a default value in the repeater field like this (note: you need to do these edits in the PHP export code. Note 2: Check the ‘default_value’ key passed to the array):
array (
'key' => 'key_58c7ee3a37aee',
'label' => 'Table',
'name' => 'table',
'type' => 'repeater',
'instructions' => '',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'collapsed' => '',
'min' => 0,
'max' => 0,
'default_value' => array(
array(
'field_58984ddb5b8cc' => 'My title',
'field_58985045abac0' => 'My content',
),
array(
'field_58984ddb5b8cc' => 'Another title for a content-less row',
),
),
'layout' => 'table',
'button_label' => 'Add Row',
'sub_fields' => array (
array (
'key' => 'field_58984ddb5b8cc',
'label' => 'Title',
'name' => 'title',
'type' => 'text',
'instructions' => '',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '40%',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
'readonly' => 0,
'disabled' => 0,
),
array (
'key' => 'field_58985045abac0',
'label' => 'Content',
'name' => 'content',
'type' => 'text',
'instructions' => '',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '60%',
'class' => '',
'id' => '',
),
'default_value' => '',
),
),
),
Hope this saves someone’s time,
Cheers !
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.