Tell us what you are trying to do?
Add a Toolset custom image to a Gridbuilder WP grid
Is there any documentation that you are following?
hidden link
Is there a similar example that we can see?
I am returning to an issue I never got to get working https://toolset.com/forums/topic/display-toolset-custom-image-field-in-gridbuilder-wp/
I have made some updates to the code but it is still not working. Do you think it because of the way Toolset stores images?
[code]
function register_vendor_profile_image_block( $blocks ) {
// "vendor_profile_image_block" corresponds to the block slug.
$blocks['vendor_profile_image_block'] = [
'name' => 'Vendor Profile Image',
'render_callback' => 'render_vendor_profile_image_block',
];
return $blocks;
}
add_filter( 'wp_grid_builder/blocks', 'register_vendor_profile_image_block' );
function render_vendor_profile_image_block() {
// Object can be a post, term or user.
$object = wpgb_get_object();
// If this is not a post (you may change this condition for user or term).
if ( ! isset( $object->vendor ) ) {
return;
}
// You have to change "custom_field_name" to yours.
$image_id = get_post_meta( $object->ID, 'wpcf-vendor-profile-image', true );
if ( empty( $image_id ) ) {
return;
}
// You can change the image size "medium_large" to suit your needs.
$image_url = wp_get_attachment_image_url( $image_id, 'medium' );
if ( empty( $image_url ) ) {
return;
}
printf(
'<img src="%s" alt="%s" width="100%%" height="400px" style="object-fit:contain">',
esc_url( $image_url ),
esc_attr( get_post_meta( $image_id, '_wp_attachment_image_alt', true ) )
);
}
[/code]
What is the link to your site?
This is how the grid currently looks: hidden link
This is how I want the grid to look: hidden link
Thanks