This:
update_post_meta(42, 'my_meta_key', [
'my_meta_value_1',
'my_meta_value_2',
'my_meta_value_3',
]);
Changes a single post meta, but the value is an array, and you can’t put a array in the database, it wants a string for that column. So WordPress serializes it into a string and saves the result.
So I have a question, are either of these two ways of saving data better than the other?
Yes! Serialized data is bad, it’s difficult to query (sometimes imposssible), has a tiny additional overhead, and it exposes you to object deserialisation attacks.
If you want to store a list of 10 things, store 10 meta, not 1 meta with an array. If you really must do it, turn it into a comma separated list first or JSON encode it.
Related Posts:
- MySQL SELECT increment counter
- Exclude Statement in SQL
- Detecting errors generated by $wpdb->get_results()
- wpdb update add current timestamp not working
- Displaying content from one WP site on separate WP site
- Lost the `wp_options` table: what’s the best way to restore the site?
- Can a post ID be 0?
- Performance Gains of Relational DB Setup
- How to move existing WordPress wp-content folder along with database to new server and new domain name?
- what is the wp_5_posts table in the database?
- Migrating data between local and development server
- WordPress Database Charset/Collate
- store simple data in get_option()
- How might I retrieve a featured post image from an external WP site and display it as a link back?
- What is the database table for pages?
- Using Dynamic Data Pulled from a MySQL Table in a WordPress Page
- What are conventions about the schema of the $table_prefix
- WordPress database becoming huge. How to analyze and optimize it? fear of running out of memory
- BuddyPress: What’s the use of wp_bp_xprofile_data table and how does it get updated? [closed]
- What’s the most efficient database method to add and query usermeta?
- How to solve slow WordPress site caused by attachment_metadata
- Is database safe after merging a branch of a more recent version over an older one?
- Hook to be used when creating a database table
- Delete all post meta except featured image
- Large database causes slow load
- Why do wordpress store pages/posts within the database instead of files? [closed]
- Is a direct or import approach safer for migration into WordPress?
- Insert custom data to custom table on wordpress database
- How does WordPress store data?
- Merging WordPress posts from different databases
- Select Multiple meta_value from WP DB; Single Query
- One post carries 30 postmeta values, is this too much?
- Is it possible to split database tables using HyperDB?
- What happens if I overwrite the current wp_options table with a backup from a week ago?
- Critical error in final stage of website launch – URLs are BROKEN!
- How do I get WordPress login to ignore the password input if a particular username is used?
- Migrating WordPress from DreamHost to Azure WordPress Resource via UpdraftPlus “wp_options table does not exist…” error
- “Error establishing a database” connection on some sites
- How to Mirror WordPress database from Remote server to Local server
- WordPress is not creating table in database after activating plugin,
- Is MariaDB’s Aria storage engine suitable for WordPress?
- How do I delete these post types in my WordPress database?
- Slow queries constantly getting stuck on WordPress database of ~100,000 posts
- How do I query wp_options for expired transient pairs with MySQL commands?
- data (html) migration to posts
- WordPress running SQL query to update database from form
- How to fix database error duplicate entry
- Use same database on main domain & sub domain
- How do I convert a MySQL database from utf8mb4 to utf8 encoding?
- WPDB SQL query with prepare() returning variable, not db value
- Get value form wordpress database
- Why user_pass column in wp_users table is varchar(64)
- Why this query is not showing any result on wordpresss home page?
- How to migrate a database from a server to another
- How to display content from external db with relevant urls
- Reinstalling wordpress from database breaks the site
- how to count click tab menu and insert to database
- Adding prefix to WordPress database tables breaks admin capabilities?
- What is the best way to resurrect and update my old WordPress site?
- Trouble running $wpdb->query() with last_insert_id
- Using $wpdb | checking entered email against existing emails in db
- content disappearing minutes after it’s published
- wp-cli: Error establishing a database connection: undefined constant DB_USER
- Add pdf to a website
- Optimizing function that automatically creates internal links based on post title string
- Can I customised default WP table
- Woocommerce – Check product stock availability from external database
- Get results from wordpress data custom table
- Outputting query results
- Help With a Large WordPress Based MySQL Database on Shared Hosting
- Database migration issues – Error #1046 No database selected
- Can two domains use the same database?
- Search Character Set Problem
- _wp_attachment_metadata is not being added to database when PDF files uploaded
- How to get the full stack trace for WordPress “table doesn’t exist” error in debug.log?
- How to fix Uploaded to this post option to see group of images uploaded to a post?
- adding user_id and name to a separate table whenever a user register based on role
- How to access a table in a wordpress database using REST API?
- How do I loop/iterate through posts to edit all img tags?
- User saved through WordPress backend does not show up in database table users
- How to optimise this database query?
- How to retrieve user data based on role using SQL?
- Adding featured for post using database
- Missing latest posts and options after DB migration via phpMyAdmin
- get_the_terms is not working
- Store id from database query in cookie
- Split database on large site?
- Store the wordpress “featured image” under »wp_posts« Database table
- Return image urls with specific base string?
- What WordPress file is saving new users to database
- Restoring .sql backup results in “Error establishing a database connection”
- Link to handle $_GET request
- WordPress sync with phpbb
- “MySQL server has gone away” since update to 3.8
- Getting deleted users in database
- Getting data from a table using a query
- Database interaction (private-public) [closed]
- SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta
- WP Multisite Users Not Linking
- Query a meta key using an array of values where the database value is a string