admin管理员组文章数量:1122832
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?
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?
Share Improve this question asked Mar 9, 2022 at 21:27 clayRayclayRay 1351 silver badge10 bronze badges1 Answer
Reset to default 0Not sure if you have already resolved your issue, but I am in a similar situation. You could take a look at this webpage for guidance:
https://wpdevdesign.com/how-to-create-custom-blocks-in-wp-grid-builder/
本文标签: filtersHow to show ACF fields in Gridbuilder custom block
版权声明:本文标题:filters - How to show ACF fields in Gridbuilder custom block 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736296910a1929899.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论