You can json_encode()
it which will make it a string that you can put into a custom field then just ensure you json_decode()
it to bring it back to an object or json_decode($data, true)
to bring it back as an array
$arr = array("Accounting"=>"Peter", "Finance"=>"Ben", "Marketing"=>"Joe");
update_post_meta($post_id, "my_custom_meta_key", json_encode($arr));
$json_data = get_post_meta($post_id, "my_custom_meta_key", true); // true to ensure it comes back as a string and not an array
$arr_data = json_decode($json_data, true); // 2nd parameter == true so it comes back as an array();
Related Posts:
- Can I query custom meta data through WP_Query
- When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
- WP doesn’t show Array Custom Fields?
- How do I search an array stored in a custom-field using WP_Query?
- Is it possible to store arrays in a custom field?
- use get_posts to get custom field data, but in one array
- Get specific custom field keys from a post and put into an array
- WP Query Returning All Posts
- Passing Custom Field Data as Array to be Saved (Resulting Custom Field Array is inconsistent)
- Run a check for multiple meta key values
- Create an Array of Specific Custom Post Meta
- Remove Body Classes
- Sort alphabetically by custom field
- change order of images attached to post
- query_posts with meta_value
- Displaying an ACF list of users
- Meta value Array
- Custom field to array?
- Show array of meta_value in Edit Post Coloum
- How to Convert Custom Fields from Text to Array?
- Custom field outside the loop and inside an array
- Get custom post fields from multiple metaboxes
- Working with multiple values and metaboxes
- Custom Field: how to save array of multiple key-values in WordPress
- How to save array option as text and not integer?
- Should I store arrays in custom fields or create custom tables?
- How do I use foreach to get content from a custom-field in multiple posts?
- Adding custom field to an array
- How do i output images from URL’s added to the same custom field key
- Extract array from custom field
- Build Array from Input Fields question
- Custom fields: Split data from single custom field’s sub-array to separate custom fields when saving post
- How to add a custom field in the advanced menu properties?
- Sortable Custom Columns in User Panel (users.php)?
- Importing data for advanced custom fields plugin?
- Gutenberg add a custom metabox to default blocks
- How to rename a custom field?
- Filter post listing by meta value which is a date
- How to activate “custom fields” section in WP3
- Add meta data to the menu
- Copy SEO Meta Desc “Custom Field” to Excerpt field?
- Custom fields won’t display on my blog page
- How to customize default wordpress editor?
- Order Custom post type loop by custom field (datepicker)
- Show posts on a Google Map
- Change the RSS Publication Date to use a value from a custom field
- Compare WP Custom Field date
- Leader board for game on homepage
- Count how many posts have a custom field set
- Update posts after populating ACF field value [closed]
- Adding custom fields (post meta) before/during wp_insert_post()
- Custom field as meta description
- post meta getting deleted on save
- Display WP-Types custom fields in post [closed]
- Checkboxes in registration form
- how to fetch the meta field keys/meta boxes from a post type?
- Calling the “wp-link-wrap” pop-up modal
- Shortcode To Display Post Custom Field Value Inside Excerpt
- Limit the number of acf content when displaying in post loop [closed]
- How do I add an image upload, custom field to a WooCommerce product?
- displaying and sorting comments by a custom field (using PODS plugin) [closed]
- how to display a widget only on a page where the custom field is defined?
- Show values of custom post meta on ‘Add new post’ page?
- Custom tables or custom fields?
- display custom field from inner blog in the main homepage of wordpress multisite
- Post selector as Custom Field
- Multiple URLS per post non-ascii
- Display Custom Meta Box Field Only If Value is Present
- Am I overusing custom fields (for adding nearly 5 images and their titles)?
- WP Query – Is this correct?
- How to remove custom fields from the selector?
- What is the proper way to add a required field to a post type? [duplicate]
- How can I combine this php statement to get the results of multiple variable inputs?
- Access ACF fields within custom preview function?
- Scripts and tags will not save or output from my custom meta box
- Using WP Color Picker in Repeatable Fields
- How do I save Multiple fields in a meta box?
- Can I access Posts of custom-fields via URL?
- Output custom field value
- Best way to achieve multiple links in a post title
- plugin-list-category-post custom fields
- How to display data from custom fields I created?
- Get array of posts based on custom field values
- How to automatically change a posts status to draft based on custom field
- How to show ACF fields in Gridbuilder custom block
- Display taxonomy loop using custom field data
- Adding more fields to the registration form
- use mysql to replace one custom field value with another custom field value
- Change blog post title on main blog page
- Spit out list of distinct instances of custom field?
- Filter and display a specific custom field value [closed]
- Is it possible in WordPress
- Edit different parts of a page seperately
- I want my post to republish again after adding a custom field
- Custom fields: dropdown values depending on other custom field value
- Creating an If/Else statement using WPAlchemy MetaBox radio boxs
- Media Custom Fields – get a value with PHP
- jaredatch metaboxes on video post formats
- Truncating characters in Advanced Custom Fields works some places but not others?
- How to add an ACF only for parent term?