
Great! Thank you very much. Grabbed the code and adjusted to me need where i only want to query one option. In case someone needs it as well:
add_action("rest_api_init", function () {
register_rest_route("options", "/clients", [
"methods" => "GET",
"callback" => "acf_options_route",
]);
});
function acf_options_route() {
return get_field('lmdm_clients','option');
}
lmdm_clients is a repeater field in this case…

found a workaround in case someone needs similar code… i show/hide field groups based on another acf field value i use in an option page:
add_filter('acf/get_field_group', 'my_change_field_group_priceinfo');
function my_change_field_group_priceinfo($group) {
if($group['title'] != 'Preisinfo') return $group;
if(!get_field("priceinfo","options)){
require_once ABSPATH . 'wp-admin/includes/template.php';
\remove_meta_box('acf-'.$group["key"], 'post', $group["position"]);
}
return $group;
}

my case is simpler. i just want to hide the field group in the post editor for certain conditions. i can hide/disable the fields simply with acf/load_field hook but then i have an empty field group left.

i have a very similar setup where i init the acf field groups and fields through a custom plugin with acf/include_fields and need to overwrite a field setting via child-theme. would be nice to see a build in filter in acf/include_fields hook or in acf_add_local_field_group function

today i had some capacities to give it a try. because there is a viewScript node, i discovered there is also a viewStyle node. And both are working similar. They both load the assets only if the block i actually used. But viewStyle loads the file as inline-css in the <body>. So this seems finally solved for me.
my old code:
"style": ["file:./assets/tabgroup.css","tabgroup"],
"script": ["file:./assets/tabgroup.js","tabgroup"],
recent working code:
"viewStyle": ["file:./assets/tabgroup.css","tabgroup"],
"viewScript": ["file:./assets/tabgroup.js","tabgroup"],

because acf does not passes the correct post id of each post in the query. instead it returns the post id of the query loop post. every post in that loop get the same id. therefore it won’t work as get_field always tries to return the values of the loop containing post.

what do you think what i am? A machine? I can not read your comment / code. So i can not help you. But placing custom content before/after something is just like changing the order in the code. code for outputting the acf field after the title:
add_filter( 'render_block_core/post-title', function( $block_content, $block ) {
if(!empty($block["attrs"]["className"]) && $block["attrs"]["className"] != "company") return $block_content;
return sprintf("%s<div style='margin-top:%s'><strong>%s</strong></div>",$block_content,"10px",get_field("company"));
}, 10, 2 );

check out my query loop solution with some custom code

Hi Guys – just want to share my workaround idea here…
assuming you want to place a custom field value before (or after) the post-title block in the loop template, you can give the block a unique classname like in my case “company” and then look for that classname in the following code you need to put in your functions.php
add_filter( 'render_block_core/post-title', function( $block_content, $block ) {
if(!empty($block["attrs"]["className"]) && $block["attrs"]["className"] != "company") return $block_content;
return sprintf("<div style='margin-bottom:%s'><strong>%s</strong></div>%s","10px",get_field("company"),$block_content);
}, 10, 2 );
thats a pretty robust solution because it uses core code. In my case i need to output the custom field “company” before the post title in of one post in the loop. This will work for the frontend only!

@alessietto simplified you need to change your markup.
this is my first block type “tabgroup”:
<div class="tabgroup" id="<?php echo $block_id; ?>">
<InnerBlocks allowedBlocks="<?php echo esc_attr( wp_json_encode( array( 'tabitem' ) ) );?>" template="<?php echo esc_attr( wp_json_encode( array(array('tabitem')) ) );?>" />
</div>
this is my second block type “tabitem” which is a child of tab_group:
<div class="tabitem">
<InnerBlocks />
</div>
tabitem needs the json-key:
"parent" : ["tabgroup"]
or if you work oldschool with php array:
"parent" => array("tabgroup")
in the end you need to order the items and play with visibility via css like:
.tabwrapper { display:flex }
.tabitem { order: 0 }
.tabgroup { order: 1 }
check this article to understand the logic

sorry for late reply. yes. according to acf6 you now should use register_block_type (instead of acf_register_block_type) and load the block.json file. Example:
{
"name" : "lmdm/tabitem",
"title" : "Tab-Inhalt",
"description" : "Tab-Inhalt",
"category" : "widgets",
"icon" : "<svg width=\"80px\" height=\"80px\" viewBox=\"0 0 80 80\" xmlns=\"http://www.w3.org/2000/svg\">\n <g id=\"icon-tab-item\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n <path d=\"M31.0453442,11.6287145 L31.0453442,27 L75,27 L75,75 L5,75 L5,27 L10.2507421,27 L10.2507421,11.6287145 L31.0453442,11.6287145 Z\" id=\"Rectangle\" stroke=\"#000000\" stroke-width=\"4\"></path>\n <rect id=\"Rectangle\" fill=\"#000000\" x=\"13\" y=\"35\" width=\"54\" height=\"32\"></rect>\n </g>\n</svg>",
"keywords" : ["tabs","navi","accordion","accordeon"],
"parent" : ["lmdm/tabgroup"],
"supports" : {
"align" : false,
"align_text" : true,
"multiple" : true,
"color" : {
"background": false
},
"jsx" : true
},
"acf": {
"mode": "preview",
"renderTemplate": "index.php"
}
}

yes thats my current status quo. you can load ONE js-file with the handle passed through “script” key. But i need to load multiple js-files. so this won’t work at the moment:
{
"script": ["block-qb-daterange","another-handle"],
}

i found out i can get rid of the post status if i simply add
‘post_status’ => ‘publish’,
to the query. but to be honest i am not sure if it influences the performance. what else can be done here?

thank you guys, was looking for this!

sure. you can also add
'color' => array(
'link' => true
)

okay i think i got it now. parent attribute needs to be placed in acf_register_block_type:
acf_register_block_type(array(
'name' => 'tab_item',
'title' => __('Tab-Inhalt','hns'),
'description' => __('Tab-Inhalt','hns'),
'render_template' => 'template-parts/blocks/tabs/tab-item.php',
'category' => 'widgets',
'keywords' => array( 'tabs','navi'),
'mode' => 'preview',
'parent' => array('tabs_group'),
'supports' => array(
'align' => false,
'align_text' => true,
'multiple' => true,
'jsx' => true, // innerblocks
//'align_content' => true, // oben, mittig, unten
),
));

was looking for the exact same case. building my own tabbed content block.
the approach of @dsouzaj86 works pretty well. I tried it. thank you very much! Only thing i don’t get is the parent property to allow appearing the tab-content only in tab-group. at the moment i can place it everywhere.
tab-group:
<InnerBlocks allowedBlocks="<?php echo esc_attr( wp_json_encode( array( 'acf/tab-item' ) ) );?>" />
tab-item:
<InnerBlocks parent="<?php echo esc_attr( wp_json_encode( array( 'acf/tab-group' ) ) );?>" />
seems parent gets ignored.

if you want to NOT have the cpt translatable by polylang you need to skip it in parse_query hook like this:
function skip_cpts( $query ) {
if ( get_post_type() == "event" ) $query->set( 'lang', '' );
}
add_action( 'parse_query', "skip_cpts", 0 );
thanks to polylang support if found this solution helpful

WOW finally i found the issue. It occurs when you use Polylang and you did not put the CPT in CPT-settings of the plugin:

i simply forget it and this was driving me crazy for hours. JC! hopefully one day i can help someone with that monologue or ACF team will implement a fix

one thing i tested: as it used to work with older/other CPTs, i duplicated one post of other CPT and then changed the posttype in the database to “event” and voila, it gets accepted and saved by the relationship field: https://www.loom.com/share/ae811648893d4251bb2e8ef5c9851ad7
but i don’t see/understand the difference of the posts


subscribed!

i am late but you can also try something like this (with type):
function disable_acf_load_field( $field ) {
$field['disabled'] = true;
return $field;
}
add_filter('acf/load_field/type=text', 'disable_acf_load_field');
or try to inspect $field array name with matches of your fields like:
function disable_acf_load_field( $field ) {
$fields = "project_code","project_type","project_status","funding_year" // add more here
if(in_array($field["name"],$fields)) $field['disabled'] = true;
return $field;
}
add_filter('acf/load_field/type=text', 'disable_acf_load_field');

i was not aware of “FrmForm::get_published_forms()”. Your code is definitely better 😉

as far as i can see this plugin won’t work in the future too
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.