Custom Fields
Re-Envisioned
Support MB Custom Table rwmb_meta not working for Custom Table

  • Creator
    Topic
  • #29621
    AB
    Participant

    I 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.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Author
    Replies
  • #29629
    Long Nguyen
    Moderator

    Hi,

    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.

    #29631
    AB
    Participant

    This is the data in DB. It clearly shows post ID = 2.

    db

    The custom table is created via the Web GUI, there is no code. screenshot below:

    web

    This is the creation of fields:

    field

    #29632
    Long Nguyen
    Moderator

    Hi,

    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;
    #29633
    AB
    Participant

    Yes 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.

    #29635
    AB
    Participant

    Just 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;
    #29636
    AB
    Participant

    So 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.

    #29637
    Long Nguyen
    Moderator

    Hi,

    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.

    #29638
    AB
    Participant

    Hi, 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.

    #29644
    Long Nguyen
    Moderator

    Hi,

    It's so weird. Please try to follow the Debugging Information step here https://metabox.io/support/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.

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.