Home › Forums › Add-ons › Flexible Content Field › Default Flex content with acf/load_value: Default layouts load, but not content
I’m using the “acf/load_value” filter to provide a default flex content template for a specific post type. So far I’ve managed to load default layouts just fine, but any content I try to put in them will not appear. Can someone help me find what I’m doing wrong?
This is my filter function:
function default_page_blocks_room( $value, $post_id, $field ) {
$new_value = $value;
$post_type = get_post_type( $post_id );
// La valeur ne sera null que si c'est une nouvelle page
if( null === $value ) {
if( 'room' == $post_type ) {
$new_value = [
[
'acf_fc_layout' => 'small_gallery_text',
'text' =>
'<h2>' . __("Description", 'bonestheme') . '</h2>'
. '<p>' . __("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas varius tortor nibh, sit amet tempor nibh finibus et. Aenean eu enim justo.", 'bonestheme') . '</p>'
. '<ul class="half-width-blocks">'
. '<li>'
. '<strong class="large-text">' . __("Donec libero turpis, lacinia nec leo sit amet, dignissim dignissim lacus.", 'bonestheme') . '</strong>'
. '</li>'
. '</ul>'
],
[
'acf_fc_layout' => 'image_text_juxta'
],
[
'acf_fc_layout' => 'large_gallery',
'title' => __("Galerie d'images", 'bonestheme'),
],
];
}
}
return $new_value;
}
add_filter('acf/load_value/name=page_blocks', 'default_page_blocks_room', 10, 3);
One of my layouts is defined as such:
'small_gallery_text' => [
'key' => 'layout_page_blocks_small_gallery_text',
'label' => __("Petite galerie avec texte", 'bonestheme'),
'display' => 'block',
'name' => 'small_gallery_text',
'sub_fields' => [
[
'key' => 'field_page_blocks_small_gallery_text_gallery',
'label' => __("Galerie d'images", 'bonestheme'),
'instructions' => __("La première image s'affichera en grand par défaut.", 'bonestheme'),
'name' => 'gallery',
'type' => 'gallery',
'wrapper' => [ 'width' => 50 ],
],
[
'key' => 'field_page_blocks_small_gallery_text_text',
'label' => __("Texte adjacent à la galerie", 'bonestheme'),
'name' => 'text',
'type' => 'wysiwyg',
'wrapper' => [ 'width' => 50 ],
],
],
],
To populate the fields in the layout you need to use the field keys instead of the field names.
'field_page_blocks_small_gallery_text_text' =>
'<h2>' . __("Description", 'bonestheme') . '</h2>'
. '<p>' . __("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas varius tortor nibh, sit amet tempor nibh finibus et. Aenean eu enim justo.", 'bonestheme') . '</p>'
. '<ul class="half-width-blocks">'
. '<li>'
. '<strong class="large-text">' . __("Donec libero turpis, lacinia nec leo sit amet, dignissim dignissim lacus.", 'bonestheme') . '</strong>'
. '</li>'
. '</ul>'
The topic ‘Default Flex content with acf/load_value: Default layouts load, but not content’ is closed to new replies.
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.