Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How to save custom made object in an array in a post meta field

Arrays and objects get automatically serialized/unserialized because they are php data types being stored as strings by MySQL. If you save array with update_post_meta you don’t need to unserialize the returning value get_post_meta, function will do it for you.

Easier to look at update_post_meta function’s source code. It calls update_metadata function where you can see a call of this function:

maybe_serialize( $meta_value );

As you can see, if data is array or an object type – it will serialize this data.

function maybe_serialize( $data ) {
    if ( is_array( $data ) || is_object( $data ) ) {
        return serialize( $data );
}

From the other side, when you use get_post_meta function, this chain is bigger, but at the end it calls maybe_unserialize function, which do unserialization if needed.

maybe_unserialize( string $data )

In your case you are trying unserialize unserializable string. serialize() function returns false and generates E_NOTICE if it can’t unserialize a value.

Related Posts:

  1. Get menu object from theme_location
  2. How to include one class/instance without using global variables
  3. syntax for remove_filter in parent theme with class
  4. Add options to featured image
  5. Change meta tags programatically
  6. Use a function to update post meta based on other post meta
  7. update_post_meta for custom field not working upon form submission
  8. Assign category using custom field?
  9. Convert User ID’s to User Names in a single.php file
  10. restore_current_blog required after switch_to_blog, if I use that in a function?
  11. Can’t check if a post has thumbnail adding filter to get_post_metadata()
  12. Move Post to different category if post_meta field is 0 or is 2 days old?
  13. What WordPress function to use to get meta value by using meta keys?
  14. Default Custom Field Value Automatically Update
  15. Post meta not updating
  16. Function to update post_meta based on existing post_meta
  17. Exclude from the query posts with meta_key and meta_value
  18. Prevent custom field from being updated after first publish
  19. Get array of metakey in all posts
  20. User function to return multiple get_post_meta()
  21. What are the meta fields for an attachment?
  22. How to avoid saving empty data to sql while using add_meta_box
  23. How to change text color depending on the number value (Using javascript)
  24. How to add custom metakey to shop_order page’s searching function?
  25. Update wp_postmeta table based on 2 keys
  26. blank page with wp_get_attachment
  27. Child theme, how to cut the functions.php file into several classes?
  28. Pass an argument into a function to extract from array
  29. Reference multiple style sheets, clearing styles for permalink page, custom fields for css
  30. How To Display Author Popup on Entry Meta (Genesis Framework)?
  31. Creating a “Related Meta” type field?
  32. Remove post from latest posts after a month only with certain tag
  33. save_post doesn’t correctly process function call with php class
  34. Return ACF Field value function
  35. update_post_meta not working in function
  36. How To Get WordPress Categories Last Update Date?
  37. How to add a meta information to the URL?
  38. Automatically add custom fields (post_meta) to all published posts, hourly, via wp_cron?
  39. update_post_meta after form is submited
  40. Add custom fields after post/page title
  41. Display post_meta-by_key on product catalogue
  42. Adding and updating repeating custom field meta data
  43. How can I modify or filter this variable in an existing class? (Mai Theme)
  44. Missing feature image link function
  45. What’s the difference between home_url() and site_url()
  46. Remove “Category:”, “Tag:”, “Author:” from the_archive_title
  47. get_template_directory_uri pointing to parent theme not child theme
  48. How to customize the_archive_title()?
  49. remove empty paragraphs from the_content?
  50. What is the “with_front” rewrite key?
  51. Why use if function_exists?
  52. How to override parent functions in child themes?
  53. wp_enqueue_script was called incorrectly
  54. Add multiple custom fields to the general settings page
  55. Ajax call always returns 0
  56. 400 bad request on admin-ajax.php only using wp_enqueue_scripts action hook
  57. How long does a deprecated function live in core?
  58. Solution to render Shortcodes in Admin Editor
  59. How to add a data attribute to a WordPress menu item
  60. What’s the difference between esc_html, esc_attr, esc_html_e, and so on?
  61. remove_action on after_setup_theme not working from child theme
  62. plugins_url vs plugin_dir_url
  63. Remove type attribute from script and style tags added by WordPress
  64. How to run a function every 5 minutes?
  65. Best way of passing PHP variable between partials?
  66. Upload Multiple Files With media_handle_upload
  67. How to display custom field in woocommerce orders in admin panel?
  68. Adding fields to the “Add New User” screen in the dashboard
  69. Issues with title-tag and document_title_parts
  70. How do I get the current edit page ID in the admin?
  71. How to check if a user exists by a given id
  72. Why isn’t is_page working when I put it in the functions.php file?
  73. Add tags to the section via functions.php
  74. Add image size if page template
  75. How to create a custom order status in woocommerce!
  76. Remove Actions/Filters added via Anonymous Functions
  77. Adding a second email address to a completed order in WooCommerce [closed]
  78. How to load parent_theme functions.php before child_theme?
  79. How to load scripts/styles specific for a page
  80. Programatically add options to “add new” custom field dropdown
  81. Is there any global functions.php file which works for any theme?
  82. Excluding iPad from wp_is_mobile
  83. Using classes instead of global functions in functions.php
  84. When should you, and when should you not, use wp_list_pluck()?
  85. Get the ID of the page a menu item links to?
  86. Add container to nav_menu sub menu
  87. Difference between the_permalink() and get_permalink() function
  88. What’s the difference between WordPress random_int() and PHP built-in function random_int()?
  89. Child theme – Overriding ‘require_once’ in functions.php
  90. Link to user’s profile settings page?
  91. WordPress Enqueue for homepage only, functions.php, wp-framework
  92. get php variable from functions php and echo it in theme template files [closed]
  93. Is it ok to use a function to output the text domain name in a wordpress theme
  94. Displaying the number of updates available in the Admin area
  95. Trying to use add_action and do_action with parameters
  96. Use AJAX in shortcode
  97. Set JPEG compression for specific custom image sizes
  98. Can the new 4.8v text widget visual editor be removed?
  99. Prevent “main” WPMU site_url() being returned in functions
  100. Include files in child theme functions file
Categories functions Tags functions, oop, post-meta
Snippet displaying LearnDash parent course title with lesson title [closed]
404 Not Found nginx on wp-admin

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress