Hi,
im pretty sure im doning something wrong. It´s my first time with local json.
I want to register a Block, and then load the json for that block.
But i dont get it work. What im doing wrong or ist not possible ?
I can select the Block, but the Text Field is not showing up inside the block. It´s just an empty block.
<?php
add_action('acf/init', 'my_register_blocks_json');
function my_register_blocks_json() {
// check function exists
if( function_exists('acf_register_block') ) {
// register a testimonial block
acf_register_block(array(
'name' => 'testimonialjson',
'title' => __('Testimonial Json'),
'description' => __('A custom testimonial block. Json'),
'render_callback' => 'my_acf_block_render_callback_json',
'category' => 'formatting',
'icon' => 'admin-comments',
'mode' => 'preview',
'keywords' => array( 'testimonial', 'quote', 'json' ),
));
}
}
function my_acf_add_local_field_groups_json() {
// remove original path (optional)
//unset($paths[0]);
// append path
$paths[] = get_stylesheet_directory() . '/includes/blockytwo';
$paths[] = get_template_directory() . '/includes/blockytwo';
$paths[] = get_stylesheet_directory() . '/includes/blockytwo/';
$paths[] = get_template_directory() . '/includes/blockytwo/';
$paths[] = 'D:/xampp/htdocs/wp5/wp-content/themes/enky/includes/blockytwo';
$paths[] = 'D:/xampp/htdocs/wp5/wp-content/themes/enky/includes/blockytwo/';
$paths[] = 'http://localhost/wp5/wp-content/themes/enky/includes/blockytwo/';
$paths[] = 'http://localhost/wp5/wp-content/themes/enky/includes/blockytwo';
//print_r($paths);
// return
return $paths;
}
add_action('acf/settings/load_json', 'my_acf_add_local_field_groups_json');
function my_acf_block_render_callback_json( $block, $content = '', $is_preview = false ) {
/* print_r($block);
print_r($content); */
$headlinegt = get_field('acf_onetextcolum_headline_json');
?>
<section class="tp-text-onecolumn-gutenberg">
<div class="container">
<div class="row">
<div class="col-12">
<div class="headline-container">
<h2 class="headline"><?php echo $headlinegt;?></h2>
</div>
</div>
</div>
</div>
</section>
<?php
};
?>
[
{
"key": "group_json",
"title": "One Column Text Json",
"fields": [
{
"key": "field_5c0a4fd48b754_json",
"label": "Headline",
"name": "acf_onetextcolum_headline_json",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": ""
}
],
"location": [
[
{
"param": "block",
"operator": "==",
"value": "acf\/testimonialjson"
}
]
],
"menu_order": 0,
"position": "normal",
"style": "default",
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": "",
"active": 1,
"description": ""
}
]
The topic ‘Register Block / Local Json’ 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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.