filters – How to show ACF fields in Gridbuilder custom block
I’m using GridBuilder WP (great plugin, average support) to show a grid of a custom post type. Ultimately, I need to show an ACF taxonomy field, and their support have recommended using one of their nifty Custom Blocks, but at the moment I’m struggling to just show a text field (as a test) in a Custom Block. This is the suggested code, but it always shows the label “Email” with an empty field, even though there is a normal block above showing the custom field successfully.
add_filter(
'wp_grid_builder/blocks',
function( $blocks ) {
$blocks['email_block'] = [
'name' => __( 'Email block', 'text-domain' ),
'render_callback' => function() {
// Get email from ACF field.
global $post;
$post = wpgb_get_post();
setup_postdata( $post );
$email = get_field('email');
if( $email ) {
printf(
'<a href="mailto:%1$s" rel="external noopener noreferrer" target="_blank">%2$s</a>',
esc_attr( rawurlencode( $email ) ),
esc_html( 'Email' )
);
}
wp_reset_postdata();
},
];
return $blocks;
}
);
Has anyone managed to show custom fields in a Gridbuilder WP custom block?
Leave an answer