Custom Table for Taxonomy with WPGridbuilder
Support › MB Custom Table › Custom Table for Taxonomy with WPGridbuilderResolved
- This topic has 4 replies, 2 voices, and was last updated 3 years, 4 months ago by
Trang Nguyen.
-
AuthorPosts
-
June 2, 2022 at 12:36 AM #36279
Trang Nguyen
ParticipantHi!
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
June 2, 2022 at 11:07 AM #36287Long Nguyen
ModeratorHi,
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'];June 3, 2022 at 3:07 AM #36299Trang Nguyen
ParticipantHi! 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!
June 3, 2022 at 10:19 AM #36301Long Nguyen
ModeratorHi,
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/
June 3, 2022 at 5:44 PM #36316Trang Nguyen
ParticipantThank you for your help!
-
AuthorPosts
- You must be logged in to reply to this topic.