Support Forum
Support › MB Custom Table › Custom Table for Taxonomy with WPGridbuilderResolved
Hi!
I'm using WPGridbuilder to query the terms of a custom taxonomy.
I have a Single Image field and want to use it as feature image for terms.
WPGridbuilder provided this code to show the Single Image field:
function set_custom_card_thumbnail( $object ) {
// Get settings of the current grid.
$grid = wpgb_get_grid_settings();
// If it does not match the grid ID 1.
if ( 1 !== $grid->id ) {
return $object;
}
// You have to change "custom_field_name" by yours.
$image_id = get_term_meta( $object->ID, 'custom_field_name', true );
if ( ! empty( $image_id ) ) {
$object->post_thumbnail = $image_id;
}
return $object;
}
add_filter( 'wp_grid_builder/grid/the_object', 'set_custom_card_thumbnail' );
The code works perfect for a single image field with data is stored in post_meta.
But I don't know how to use it when I store the single image field data on a custom table.
Please help! Thanks
Hi,
Please follow the documentation to know how to get the image ID from a custom table
https://docs.metabox.io/extensions/mb-custom-table/#getting-field-value
https://docs.metabox.io/fields/single-image/#template-usage
// You have to change "custom_field_name" by yours.
$single_image = rwmb_meta( 'custom_field_id', ['storage_type' => 'custom_table', 'table' => 'your-table-name', 'object_type' => 'term'], $object->ID );
$image_id = $single_image['ID'];
Hi! Thank you for your reply.
I could get the image from the custom table but I couldn't use other size of its except the thumbnail. I tried this code but it always use the thumbnail instead of the large size:
<?php
$term_id = get_queried_object_id();
$image = rwmb_meta( 'my_image', ['object_type' => 'term'], $term_id, ['storage_type' => 'custom_table', 'table' => 'my_table'], ['size' => 'large'] );
?>
<a href="<?= $image['full_url'] ?>"><img src="<?= $image['url']; ?>"></a>
Could you please help! Thanks!
Hi,
All extra arguments must be added in the second parameter (array)
$image = rwmb_meta( 'my_image', ['object_type' => 'term', 'storage_type' => 'custom_table', 'table' => 'my_table', 'size' => 'large'], $term_id );
Please read more on the documentation https://docs.metabox.io/functions/rwmb-meta/
Thank you for your help!