cloneable groups - json vs serialized string

Support MB Frontend Submission cloneable groups - json vs serialized string

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #44780
    Nicholas CoxNicholas Cox
    Participant

    Hi

    For saving cloneable group form data you save the value in the database column as a serialized string, but upon reading about this subject it seems most people are opting to use 'json' to store the data inside one column. This allows the use of 'JSON_EXTRACT'. Is there any reason you dont use json over serialized strings?

    thanks

    Nick

    #44790
    PeterPeter
    Moderator

    Hello Nick,

    WordPress itself saves the array to the database as a serialized string and our plugin works with that standard feature. There are some benefits noted in the documentation https://docs.metabox.io/cloning-fields/#data-of-cloneable-fields

    - Works for all field types, including nested groups.
    - Works perfectly with the helper function or with WordPress's get_post_meta function (WordPress automatically deserializes string and returns an array).
    - Reduces the database size (number of rows), especially when you have nested groups of many fields.

    #44791
    Nicholas CoxNicholas Cox
    Participant

    Hi Peter

    ok thanks for the explanation, i checked out the link https://docs.metabox.io/cloning-fields/#data-of-cloneable-fields and i can see that the 'Clone as multiple' option is ideal for posts/pages but does not work for custom tables and models.

    So if i was to query serialized values using wpdb and custgom tables, then how would i query values within this?

    #44802
    PeterPeter
    Moderator

    Hello,

    If the value is serialized in the database, like group field, it is difficult to query posts by a subfield value. You can use an SQL query or a third-party plugin to do that. Please follow the documentation
    https://metabox.io/create-group-of-custom-fields-with-meta-box-group/#how-does-the-meta-box-group-save-data
    https://docs.metabox.io/extensions/mb-custom-table/#query-posts-with-wp_query

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