0

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?

1 Answer 1

0

Not 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/

2
  • 2
    Please edit your question to include the relevant information. Links to external resources are great, but link-only answers only work as long as the external link doesn't 404 on us. (See How do I write a good answer? for more info.)
    – Pat J
    Commented Nov 2, 2022 at 16:43
  • 1
    Whoops, that should be "edit your answer", regret the error.
    – Pat J
    Commented Nov 2, 2022 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.