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

WP_POSTMETA – What do these values mean inside the data structure?

WordPress will serialize arrays when saving to post meta. The data stored under the key _employer_socials in your example looks like this:

Array
(
    [0] => Array
        (
                [network] => facebook
                [url] => #
        )

    [1] => Array
        (
                [network] => twitter
                [url] => #
        )

    [2] => Array
        (
                [network] => linkedin
                [url] => #
        )

    [3] => Array
        (
                [network] => instagram
                [url] => #
        )
)

When you get the meta, WP will unserialize it for you, and it will look like above:

$employer_socials = get_post_meta( get_the_ID(), '_employer_socials', true );

You can then just work with the data as a regular array. When saving the array, WP will serialize it for you. Here are some basic functions that you can use as a starting point:

/**
 * Updates an existing network, or adds a new one if it does not exist.
 *
 * @param int    $post_id The Post ID to be updated.
 * @param string $network The name of the network to check.
 *
 * @return bool True if an update was made, false otherwise.
 */
function wpse_update_employee_social( $post_id, $network, $url ) {

    $employer_socials = get_post_meta( $post_id, '_employer_socials', true );

    // Update.
    if ( wpse_has_employer_social( $post_id, $network ) ) {
        foreach ( $employer_socials as $key => $employer_social ) {
            if ( $employer_social['network'] === $network ) {
                $employer_socials[ $key ]['url'] = $url;
                update_post_meta( $post_id, '_employer_socials', $employer_socials );
                return true;
            }
        }
    } else {
        // Add.
        $employer_socials[] = [
            'network' => $network,
            'url'     => $url,
        ];
        update_post_meta( $post_id, '_employer_socials', $employer_socials );
        return true;
    }

    // Nothing was updated.
    return false;
}

/**
 * Checks if a given network exists.
 *
 * @param int    $post_id The Post ID to be updated.
 * @param string $network The name of the network to check.
 *
 * @return bool True if the network exits, false otherwise.
 */
function wpse_has_employer_social( $post_id, $network ) {
    $employer_socials = get_post_meta( $post_id, '_employer_socials', true );
    foreach ( $employer_socials as $employer_social ) {
        if ( $employer_social['network'] === $network ) {
            return true;
        }
    }

    return false;
}

Example of adding a new employee social:

wpse_update_employee_social( 5302, 'wpse', 'https://wordpress.stackexchange.com/users/208214/user1669296' );

Example of updating an employee social:

wpse_update_employee_social( 5302, 'facebook', '#1234' );

Related Posts:

  1. I can not display meta value in extras.php and template-tags.php
  2. Negative meta_query if storing multiple post_meta values with shared meta_key
  3. Multiple meta key and value search in the query
  4. Meta compare with date (stored as string) not working
  5. How to get all term meta for a taxonomy – getting term_meta for taxonomy
  6. How metadata API works?
  7. Job of meta_key meta_value fields in database tables
  8. order by multiple meta_keys?
  9. How to get the total number of meta_values based on a custom post type?
  10. How to stop wp_postmeta from being called on archive and search pages?
  11. How can I convert postmeta from unserialized to serialized?
  12. How to create a meta_query to get all posts with a specific meta data?
  13. Compare meta_query with a Regular Expression and do a less-than operation on it
  14. $wpdb class updating meta_value using Ajax [closed]
  15. Should I save this mulit dementional arary as one post meta?
  16. How to check if a post meta key/value pair already exists for a specific post
  17. Order by meta value pro first then meta value free in my search function
  18. why after saving meta value it’s saving all the values the one that i clicked?
  19. Is it safe to add a new field to meta_value field?
  20. How can I use ‘orderby’ => ‘meta_value_num’ to order by the numerical value even if the value starts with a word?
  21. get Insert id for meta field
  22. Filter posts by meta key
  23. Display current ranking of post as a number in post title
  24. Search post overlapping dates – meta_query with meta_key
  25. How can I query for posts using a date stored in post-meta?
  26. Count Post and Page Views based on meta_value Using Shortcode in Dashboard Widget
  27. if get_post_meta function returns empty – Do Not Display HTML
  28. How to get posts by meta value as multi-dimensional array?
  29. How to get the total of two meta values from different meta keys?
  30. How to save a meta_value as a numeric value after I retrieve it via update_post_meta?
  31. How to update/add child posts meta whenever the parent post meta is updated?
  32. Combine meta query and give a specific meta query a higher priority
  33. Optimize WP Meta Query for large amount of post meta?
  34. Multiple postmeta values to the same post_id/meta_key combination?
  35. How to sort by meta value num, but ignore zero value?
  36. Retrieve posts from meta key
  37. How to show specific meta keys of all posts in admin panel?
  38. How to create a link for wordpress meta datas?
  39. How we insert values into database using metabox WordPress?
  40. Check for custom field value in different post type than current one and do something
  41. WP Query Args – search by meta_key or title
  42. Update post meta array – add new, single value
  43. How can I get the post ID from a WP_Query loop?
  44. How to edit a post meta data in a Gutenberg Block?
  45. How to update/delete array in post meta value?
  46. WordPress altering my custom query, How to fix it?
  47. adding a URL to a post meta
  48. Adding meta data to an attachment post
  49. Problem With Order Item Meta In Woocommerce
  50. What Is meta_id In wp_postmeta?
  51. How to add meta data to WordPress posts?
  52. Filtering multiple meta_values
  53. How add post_meta from user_meta?
  54. How can I get my iFrame to work with url from post_meta?
  55. Hey, I want the second options. get_post_meta()
  56. Update post meta in woocommerce order frontend
  57. Fetch Record based on meta key dates
  58. How can I filter posts when the meta_value is a serialize object?
  59. Get User Post if Private
  60. How to receive all the meta information of a post ?
  61. Unknown characters added to meta data values
  62. Compare old meta with new post meta
  63. get_post_meta($post->ID) returns empty string when in preview mode of custom post type
  64. Read post meta values, only if posts are public
  65. Time & Date on Post – Time Ago Custom Function
  66. Mass removing CSS from 1,700 post [closed]
  67. Filter posts by comparing custom meta value against postdate
  68. Help with Post Meta
  69. Generate metadata for cloud images
  70. Migrating meta value to new meta value
  71. How to extract data from a post meta
  72. count post meta values
  73. Correct meta of Writing Meta Tags
  74. Get post_meta from specific post [closed]
  75. Retrieve user_meta and copy to post_meta
  76. getting the post_id from the post_meta
  77. troubles with get_post_meta (and saving it)
  78. Fetch custom post related to a User
  79. How to merge the array values in foreach?
  80. Querying terms with calculations based on term meta data, sql vs. get_terms
  81. How to exclude posts by meta key value in the_post_navigation next prev links?
  82. update_post_meta not working with transition_comment_status
  83. Get meta_value from GDRating
  84. Is it possible to pass an whole array using custom field in wordpress?
  85. Attachment metadata has value of ‘1’
  86. How do I update a specific value within array in a products metadata?
  87. rendering open graph meta tags in wordpress
  88. Restore deleted _thumbnail_id in postmeta table
  89. WP Meta Query at depth 2
  90. Hide the_meta if no value
  91. php wp_insert data on front using a form
  92. Updating post_meta when updating a setting with the Settings API
  93. Media library orphans
  94. WordPress join posts with meta values of array type
  95. How to make certain content of the post noindex and no follow. not entire post?
  96. delete blank space in post_meta empty [closed]
  97. Auto save title as custom meta field value
  98. How to show wordpress post in the site based on custom field value?
  99. Extend file format support for post thumbnails
  100. Why isn’t my embed_video WYSIWYG field updating when using update_post_meta?
Categories post-meta Tags meta-query, meta-value, post-meta
WordPress User Meta & ChromePHP or other way to debug/view php variables
Can I insert elements anywhere into the results of wp_nav_menu()?

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