rwmb_meta not working for Custom Table
Support › MB Custom Table › rwmb_meta not working for Custom Table
- This topic has 11 replies, 3 voices, and was last updated 3 years, 3 months ago by
Nicholas Cox.
-
AuthorPosts
-
July 21, 2021 at 10:14 PM #29621
AB
ParticipantI have created a custom table, the values are stored properly and correctly in the DB. But I cannot retrieve the values either using PHP code or Shortcode.
To clarify, values are saved in the DB as expected. But I cannot use 'rwmb_meta' to get the data.
The tables are created automatically via web UI (with no prefix).
I tried both but nothing works:
$value = rwmb_meta( 'primary_mobile', ['storage_type' => 'custom_table', 'table' => 'ab_subscriber_info'], 2 ); echo $value;
[rwmb_meta id="primary_mobile" object_id="2" storage_type="custom_table" table="ab_subscriber_info"]
Appreciate any help.
July 22, 2021 at 9:05 AM #29629Long Nguyen
ModeratorHi,
Please make sure that
2
is the post ID that you save the field value. And please share the code that creates the custom table and fields. I will try to run the code on my end to investigate the issue.July 22, 2021 at 10:52 AM #29631AB
ParticipantThis is the data in DB. It clearly shows post ID = 2.
The custom table is created via the Web GUI, there is no code. screenshot below:
This is the creation of fields:
July 22, 2021 at 11:17 AM #29632Long Nguyen
ModeratorHi,
The table name is
wp_subscriber_info
, can you please recheck it?$value = rwmb_meta( 'primary_mobile', ['storage_type' => 'custom_table', 'table' => 'wp_subscriber_info'], 2 ); echo $value;
July 22, 2021 at 11:21 AM #29633AB
ParticipantYes I rechecked. Initial prefix was 'ab_' then I used wordpress' default prefix 'wp_' but those still dont work. The typos was because I was experimenting with different settings. Still doesnt work. Appreciate your further advise.
July 22, 2021 at 12:15 PM #29635AB
ParticipantJust to confirm, I rechecked my code and shortcode as follows and still doesn't work.
[rwmb_meta id="primary_mobile" storage_type="custom_table" table="wp_subscriber_info" object_id=2]
$primary_mobile = rwmb_meta( 'primary_mobile', ['storage_type' => 'custom_table', 'table' => 'wp_subscriber_info'], 2 ); echo $primary_mobile;
July 22, 2021 at 12:38 PM #29636AB
ParticipantSo I tried creating a new custom table for Post type. It still doesn't work when trying to get value from custom table, but saving to table is working perfectly fine. Please see all configuration below. I think there's a bug somewhere.
July 22, 2021 at 12:58 PM #29637Long Nguyen
ModeratorHi,
For the case above, user meta. You need to add the attribute
object_type
to the second argument. Get more details on the documentation https://docs.metabox.io/extensions/mb-user-meta/#getting-field-value$primary_mobile = rwmb_meta( 'primary_mobile', ['storage_type' => 'custom_table', 'table' => 'wp_subscriber_info', 'object_type' => 'user'], 2 ); echo $primary_mobile;
Please try to run the code and let me know how it goes.
July 22, 2021 at 1:05 PM #29638AB
ParticipantHi, just tried adding in object_type in the 2nd argument and still doesn’t work. Even my experiment with a normal Post type doesn’t work as above.
July 22, 2021 at 9:10 PM #29644Long Nguyen
ModeratorHi,
It's so weird. Please try to follow the Debugging Information step here https://support.metabox.io/topic/how-to-create-a-new-topic/.
If there is no error message and the helper function still does not work, please share your site credentials via this contact form https://metabox.io/contact/. I will help you to check the issue.
January 17, 2022 at 10:16 PM #33286Nicholas Cox
ParticipantHi
this is also not working for me. Returns empty value.
$value = rwmb_meta( 'city', ['storage_type' => 'custom_table', 'table' => 'wp_dc_users', 'object_type' => 'user'], 3 ); var_dump($value);
<br />upload pic<br />
January 17, 2022 at 10:24 PM #33287Nicholas Cox
Participantall metabox plugins and addons have been updated to the latest version and the problem still persists.
-
AuthorPosts
- You must be logged in to reply to this topic.