On the back end when adding/editing a new type, I have a “message” field and in that field I have a shortcode [ show_data ]
I created filters for “acf/format_value/type=message” and “acf/load_value/type=message”, but my “do_shortcode()” call is never executed when the metabox is displayed on the back end.
Is there another filter I’m missing?
Hi @dnavarrojr
Thanks for the post.
For ACF to render the shortcode markers, hooking into the acf/format_value is enough I am not sure why your shortcode is not being rendered.
How have you created you shortcode marker using the shortcode API?
Please refer to this codex when setting up your shortcodes: http://codex.wordpress.org/Shortcode_API
For ACF’s simple text values, the following syntax should be used:
[acf field="field_name" post_id="123"]
So I’m hooking into this as well and the ONLY way it seems to work is with "acf/load_field/type=message"
as the filter. problem is then the definition of the field in the acf-field-group
post gets altered as well. this is what I’ve got going on and it works:
// Allow for shortcodes in messages
function acf_load_field_message($field ) {
$type = get_post_type();
if ($type !== "acf-field-group") {
$field['message'] = do_shortcode($field['message']);
}
return $field;
}
add_filter('acf/load_field/type=message', 'acf_load_field_message', 10, 3);
It seems a little fragile and inelegant. Thoughts?
Hi @infn8
The code looks great for me. You can also use the get_current_screen() function to check the post type like this:
// Allow for shortcodes in messages
function acf_load_field_message($field ) {
$screen = get_current_screen();
if ($screen->post_type !== "acf-field-group") {
$field['message'] = do_shortcode($field['message']);
}
return $field;
}
add_filter('acf/load_field/type=message', 'acf_load_field_message', 10, 3);
Thanks!