If i create an array and convert it into JSON, will it be faster if i call 12 meta fields one by one or call the JSON, parse it and then have the variables?
Virtually no difference. The meta API means that all meta keys/fields/values are pulled into memory from the database at most once per post. So this:
$keys = [ 'this', 'that', 'then' ];
$data = [];
foreach ( $keys as $key )
$data[ $key ] = get_post_meta( $post->ID, $key, true );
…will be just as efficient as:
$json = get_post_meta( $post->ID, 'json', true );
$data = json_decode( $json );
…well, slightly optimized (reduce the get_post_meta
overhead – by which I mean PHP processing, WordPress filters etc. not database queries):
$meta = get_post_meta( $post->ID ); // No key, all metadata returned
$data = [];
foreach ( $keys as $key ) {
$data[ $key ] = isset( $meta[ $key ] ) ? maybe_unserialize( $meta[ $key ][0] ) : null;
}
Related Posts:
- PODS performance vs custom field
- Will loading too many ACF Fields cause slow down?
- Speed up / Optimize Admin Edit Post Page on Large Websites (50-150k posts, 50 custom fields per post)
- Store array as single, serialized post meta field or many post meta fields?
- How to load an assets based on custom field value?
- Best Way to get facebook share count and update using wp_schedule_event or any other method
- Why WordPress takes time to make request to save post?
- Get multiple posts with some custom fields efficient
- Can running a WP-Cron to update_post_meta cause performance issues?
- Is there a way to set default custom fields when creating a post?
- Add custom field to the archive page?
- Pre-filling custom fields on New Post
- So much data in postmeta
- Show only posts which can be commented OR have custom meta field
- Need small coding with Custom Fields Search
- Show Custom Comment Fields when editing in admin
- How do I make a custom field choose an image?
- get_post_meta() unserialize issue – returns boolean(false)
- How can I remove fields in the attachment editor?
- Edit Custom Database Tables in WordPress
- How to store the value of a custom field dropdown select for post referencing?
- Custom Meta Boxes: Store two values in one repeatable field
- Gutenberg Custom Block
- Up/Down voting system for WordPress
- Custom Meta Field not Working with qTranslate [closed]
- Change content before writing to database
- post meta data clearing on autosave
- WordPress Search Custom Meta Field Only
- Problem in custom meta boxes
- Loop through two different sets of custom fields
- Query Problem – Show posts within category ‘x’ that have a custom field between ‘y’ and ‘z’
- Add description text under input field for new profile fields
- Metabox with multiple fields added by user and upload box
- Which is best in the following scenario : post_meta vs custom table vs parent/child posts
- Get all meta keys assigned to a post type
- How to add content at the end of posts?
- sort search results by custom fields using dropdown
- WP Custom Fields Metabox Disappears – ACF plugin issue [closed]
- Get all posts that do not have a specific custom field without using a subquery
- How to query posts with certain custom meta data, and output Post data
- Custom Fields Not in Search Results
- How to associate 2 custom fields together (date & price for instance)?
- Using PHP to read WordPress Posts
- Extra option in editor
- Custom field not updating when value is empty
- Can’t get metabox value (a url) returned using WPAlchemy
- Syntax highligting for custom fields
- Displaying a checkbox array from advanced custom field
- Display custom field values from posts on frontpage
- How to create a dropdown select of all items in an ACF field group
- Custom post meta field effect on the performance on the post
- Is it possible to create a post from an NextGen Gallery image?
- Getting Custom Fields from WordPress JSON API [closed]
- Add first url to custom field on publish_post
- Use meta_query to get title of associated post
- Limits, not all post are showen when querying for posts by view count
- Advanced Custom Fields WYSIWYG More tag
- How to make custom fields respect paragraph breaks
- WordPress set custom field to true, sets all others to false?
- Shortcode To Display Post Custom Field Value in Post Title, Post Content
- How to make a customized user registration form using the built in wp-register() template tag
- Link FROM attachment to full post and get custom fields values on attachment page?
- modify wordpress custom field value – strip character if exists
- How to copy data from a custom field to the post_content?
- Sort posts by clicks on download button
- Pass PHP through redirect and custom fields
- MetaBox not saving after empty
- How can I create a profile field group that the user can’t see?
- Custom field as featured image caption
- Custom wpdb query – how to sort post by another table meta_count
- Show Custom Field of Current Page in For Loop
- Custom Field & Gravity Forms [closed]
- Redirect DRAFT Posts to a Custom URL (Custom Field) : Currently 404 Page
- Add a custom field to my custom post type and then get posts which are before the given date in the custom field
- Custom User Dashboard
- Custom Fields not working properly
- Custom meta POST request fired twice when updating a post in Gutenberg
- add meta box considers the selected option as post parent
- How do I display a custom field in an existing form on the front end?
- want to add video upload option for front end user
- Adding fields to attachment – only shows when inserting new attachments
- Saving and using Custom Field in user settings/profile “Checkbox list”
- Extend WP_User_Query or WP_User to return all custom fields?
- Quicktag button to automatically add a custom field to a post
- Display custom fields only if it has a value
- How do I use foreach to get content from a custom-field in multiple posts?
- WordPress taxonomy child image
- Create custom fields/meta data gender+country – radiobuttons and dropdown on register screen for these fields
- Add nofollow to custom field link and make domain exceptions?
- Override edit_custom_walker.php to conditionally show input depending on menu position
- wordpress simple post multi rating with post_meta and user_meta
- Change event firing in wordpress
- Download stuff after filling fields?
- Custom search with meta fields
- Use custom field value as href
- Custom registration form and custom field
- Custom field for image, not showing image!
- How can i put a custom field inside this php
- Multiple triggers when publishing, saving or updating a post in WordPress
- If possible a field ID transfom in a Custom Field?