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

Saving a meta value as an object using useEntityProp

And yet, the post meta is stored in the database as a serialized array!

This is because all meta values are strings, that’s what the database table schema says.

So if you try to pass structured data into it, WordPress tries to be helpful and uses serialize to turn it into a string, then deserialises it when it’s retrieved back. Note that this also has security consequences!. This happens for options, transients, user meta, post meta, term meta, etc etc. Anywhere that accepts arbitrary PHP data structures will serialise them down into a string so that it can still be stored. This also goes for JS data structures etc that are sent to the REST API, as well as any structured data you try to pass in via block APIs, it can’t be stored as a JS array or a PHP object, it has to be serialised into a string before it can be stored.

There are major performance and practical consequences to this too, querying for values is much harder and sometimes not possible as you can’t reliably query sub-parts of a meta value, and MySQL is unaware of any internal structure to the value. It also means if you wanted to do comparisons against your lat/long values that would not be possible.

and any way to override the way the value is saved?

You could declare it as a string and do the serialisation yourself, JSON would be a superior method, and you’d be explicit about how the data is stored.

But fundamentally it will always be a string. For this though, it could be argued that using an object in the first place is a mistake!

For example if you instead store your latitude and longitude in separate values, you can simplify your code, avoid serialising, and you gain the ability to use comparison operators in meta_query.

Generally it’s best to avoid storing structured data in post meta unless you intend to serialize it yourself and retrieve it in its entirety, e.g. a JSON or XML fragment, or content.

Related Posts:

  1. Block that displays post meta as nested block of Query Loop
  2. Where can I find the Gutenberg block icons?
  3. Add pre-publish conditions to the block editor
  4. How to filter or remove default panels in Gutenberg PrePublish Panel
  5. Deactivate Gutenberg tips forever – not Gutenberg
  6. How does Gutenberg handle translations in React?
  7. Add To Gutenberg Sidebar
  8. How to detect the usage of Gutenberg
  9. Integrate Gutenberg as a Standalone App
  10. Help Unregistering a Core Block Type in Gutenberg
  11. How to edit a post meta data in a Gutenberg Block?
  12. How do I register multiple blocks with block.json and register_block_type_from_metadata?
  13. Remove block styles in the Block Editor
  14. Disable Gutenberg text-Settings in all blocks
  15. How do I get the current post ID within a Gutenberg/Block Editor block?
  16. Looking for all available options of Gutenberg Block
  17. Possible to use @wordpress/create-block with multiple blocks?
  18. Are there ways to make the Gutenberg editor wider? And the HTML-block higher?
  19. Blocks: set a default value for a TextControl
  20. gutenberg block – how to force update after attribute changed?
  21. What is the advantage of ‘register_block_type’ (the PHP function) when creating custom blocks?
  22. How to trigger JS in gutenberg page load
  23. Allow excerpt for pages in Gutenberg?
  24. WordPress Gutenberg Embed Blocks Are Not Responsive
  25. Is there a list / reference for all current native WordPress blocks?
  26. Gutenberg: Block validation failed
  27. Set fullscreen mode by default
  28. How to query multiple post types inside Gutenberg options panel?
  29. How can I add a custom attribute to Gutenberg core blocks?
  30. Gutenberg extend core blocks
  31. Setting default font family with theme.json
  32. How can I access core/paragraph textColor in a block template
  33. (Gutenberg Block Editor) Using editor.BlockEdit filter, need to alter html/ CSS class of BlockEdit Component
  34. Add Button To Top Toolbar in Gutenberg
  35. Saving post meta using the new EntityProvider APIs
  36. Disable device preview options in the block editor
  37. Add additional classes to gutenberg .editor-styles-wrapper
  38. Implementing Gutenberg RichText onSplit / onReplace
  39. Change order/position of Gutenberg inspector control panel
  40. Get the current block ID
  41. Gutenberg Inspector Controls
  42. How to use the WordPress < LinkControl /> Component
  43. What version of Gutenberg is included with WordPress?
  44. Implement Panel Color Inspector Control in Gutenberg
  45. Add Formatting Buttons to Gutenberg core/paragraph BlockControls
  46. How do you use __experimentalLayout to give innerblocks alignment control and default layout?
  47. WordPress Value of Undefined in Admin
  48. Remove border radius setting from the Gutenberg button block?
  49. Extending Gutenberg group block: How to properly combine multiple attributes?
  50. serialize_blocks breaking html tags in content
  51. All post types with getEntityRecords
  52. gutenberg dynamic block is returning 404
  53. Modify the core/paragraph block
  54. Gutenberg how to make attribute to save to meta
  55. Add PHP block template to content using wp_insert_post
  56. The Block Editor: Disable “Color settings” in the specific block
  57. Required (mandatory) Gutenberg block
  58. How to use getBlockIndex
  59. Gutenberg reusable blocks – is it possible to customise an instance?
  60. Gutenberg InspectorControls is deprecated, how to add custom block settings?
  61. Add classname to Gutenberg block wrapper in the editor?
  62. Hide or show Gutenberg custom block using date range
  63. How to disallow a certain custom gutenberg block outside of an InnerBlocks block?
  64. How should you internationalize javascript spread in multiple files but build in one?
  65. Use page Title in Gutenberg custom banner block
  66. How to add code to `head` with WordPress 5.9 FSE (Full Site Editing)
  67. Why is onChange={ ( content ) => setAttributes( { content } )} now used?
  68. Serialize custom block with InnerBlock
  69. How to develop custom blocks without triggering validation errors
  70. Dynamic gutenberg block with react instead of php
  71. get selected categories or tags (using javascript) in GutenBerg?
  72. File structure and react setup when creating multiple Gutenberg blocks
  73. Block Editor: add an aria-label to an option inside a SelectControl
  74. WordPress Gutenberg blocks: Input fields are not editable
  75. Gutenberg withInstanceId. When to use it?
  76. Gutenberg: Get All Attributes From «core/image» Block
  77. What replaces wpColorPicker in Gutenberg?
  78. How to make the Preview button automatically open new tab?
  79. Help with using getBlockIndex
  80. How to set column widths in a CPT block template?
  81. Gutenberg: How can I disable backspace key from deleting an empty paragraph block?
  82. Access GutenBerg data with Javascript?
  83. Gutenberg moving core blocks between categories
  84. Only show focused toolbar for Gutenberg Block with Multiple text fields
  85. Gutenberg: How to Change Post Status Programmatically?
  86. What’s the recommended Gutenberg component for adding a URL, in the toolbar/sidebar?
  87. Gutenberg block get categories in SelectControl
  88. Gutenberg Range Control default from meta value
  89. Gutenberg blocks – processing server data within a block
  90. How to access “default” property of attribute in Gutenberg
  91. Adding a custom PanelColorSettings control to a core block, and using the color slug in a custom className
  92. Once Again: How to Remove Option from Gutenberg Editor for Specific Block in theme.json
  93. Gutenberg Block manipulation: Undo parse_blocks() with serialize_blocks() results in unicode issues
  94. How to use “getEntityRecords” for user data?
  95. Where on Github, or elsewhere, can I find the code for core-blocks?
  96. Find all the places where a block type is used
  97. Enhancing Gutenberg featured image control
  98. Uncaught TypeError: wp.apiFetch is not a function
  99. Why is the new Gutenberg editor so narrow, and how to make it wider?
  100. WP Blocks – Gutenberg – not rendering $content
Categories block-editor Tags block-editor, post-meta
Automatic image conversion to HEIF breaks Gallery on Safari
Change the color of one or more specific items on the Pages list (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