I think I would write a wrapper function around custom fields, something like this:
function get_post_transient( $post_ID, $meta_key, $update_function ) {
$current_value = get_post_meta( $post_ID, $meta_key, true );
if ( is_array( $current_value ) && $current_value['expiration'] < date('U') )
return $current_value['data'];
$new_value = call_user_function( $update_function, $post_ID );
update_post_meta( $post_ID, $meta_key, $new_value );
return $new_value['data'];
}
and save the meta as an array, of the form:
array(
'expiration' => //timestamp that this field exires
'data' => // all the custom data you want to save.
);
You would just need to have your update function return the same array structure. I don’t know if there’s any real benefit of this approach over using the options table through transients, but it would make more sense to me to have post meta stored in the postmeta table.
Related Posts:
- How to speed up post list slowed by update_meta_cache()?
- Can I exclude a post by meta key using pre_get_posts function?
- Custom post meta field effect on the performance on the post
- How to get custom post meta using REST API
- Difference between meta keys with _ and without _ [duplicate]
- Orderby meta_value only returns posts that have existing meta_key
- What is the index [0] for on post meta fields?
- What is “meta_input” parameter in wp_insert_post() used for?
- How to enable revisions for post meta data?
- The “_encloseme” Meta-Key Conundrum
- Best way to programmatically remove a category/term from a post
- Using get_post_meta with new_to_publish
- Custom field metabox not showing in back-end
- So much data in postmeta
- Can I count the number of users matching a value in a multiple value key?
- When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
- How to hide meta box values from custom fields list?
- Auto sort the wp-admin post list by a meta key
- get_post_meta() unserialize issue – returns boolean(false)
- What is the advantage of the wp_options design pattern?
- Storing meta fields multiple times OR once with multi dimensional array?
- Allow user to create instances of custom field
- display specific custom fields
- Is there a hook / action that is triggered when adding or removing a post thumbnail?
- Meta keywords and descriptions plugin for manually editing meta for each page/post
- passing argument to get_template_part() or a better way to code
- Is it possible to store arrays in a custom field?
- Get updated meta data after save_post hook
- Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
- Save HTML formatted data to post meta using add_post_meta()
- importing data from non-wordpress mysql db
- Create meta boxes that don’t show in custom fields
- Unable to save datetime custom meta field using update_post_meta() function
- Up/Down voting system for WordPress
- post meta data clearing on autosave
- Create custom field on post draft or publish?
- Display info from custom fields in all images’ HTML
- Ordering posts by anniversary using only day and month
- get_post_meta fields don’t show up on posts page
- Update meta values with AJAX
- How to break meta values into different items and avoid duplicates?
- copy attachments to another post type and change attachment url
- Cannot edit post meta fields with rest API
- ajax delete value from custom field array
- Save attachment custom fields on front end
- How to use pagination with get_post_meta
- Copying Custom Meta Values from existing post to a duplicate post
- Add a post meta key and value only if it does not exist on the post
- Move value of one custom field to another
- Order posts according to user defined order for meta values?
- Displaying posts with only upcoming dates according their custom field date value
- Custom fields to save multiple values
- Custom fields: In what order are they saved into the DB?
- Function to change meta value in database for each post
- Get a post_id where meta_value equals something in a serialized meta_value field
- Get aggregate list of all custom fields for entire blog
- Transition from (classical) serialized custom meta field to (gutenberg) rest enabled meta
- Unable to show ACF’s Image Custom Field properly in Genesis Framework [closed]
- Custom field value based on other custom field values
- wp_handle_upload error “Specified file failed upload test” but still creates attachment?
- How to save a ToggleControl value in a meta field?
- Which is best in the following scenario : post_meta vs custom table vs parent/child posts
- Saving custom image meta fields
- Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
- How to display Meta Field Value?
- WordPress Caching – Transients API or “update_user_meta ” Cronjob?
- MySQL query to set wp_postmeta using term_taxonomy_id value
- How to Validate Post Meta type/extension (Video File Image File etc)
- Get all meta keys assigned to a post type
- using multiple meta_key and meta_value in query_posts
- Custom Meta Box not Saving in Posts with Gutenberg Editor
- Adding custom fields (post meta) before/during wp_insert_post()
- Update Custom post field by Ajax on cached site
- Combine multiple custom field values into single value
- How can I sort homepage by a meta value?
- Get specific custom field keys from a post and put into an array
- How do I use wp_query for WordPress search?
- Nav Menu – Add class based on meta keys
- How to query posts with certain custom meta data, and output Post data
- MySQL Query that looks for post with Custom Field, then changes Category
- ACF: How to get the full field name (meta_key) by a field key?
- How to wrap meta values seperated by comma in ? [closed]
- Bulk remove post meta
- post meta getting deleted on save
- How to create html block to display extra information on woocommerce single product page
- Can’t get post ID using wp_insert_post_data
- Unique Post Meta Values
- Create Multiple File Upload Metabox in WordPress
- filtering custom post types via meta data drop down
- How to add a new meta key and assign timestamp to posts
- Run a check for multiple meta key values
- If meta key exists in get posts function otherwise create it
- Custom field not updating when value is empty
- meta_compare seems to be treating values as strings instead of integers as expected
- WordPress Rest API to call page data associate with custom meta
- Limit the number of acf content when displaying in post loop [closed]
- Read / Watch / Listen times – meta
- How to add custom metadata text box dropdown to sidebar in Gutenberg editor for all post types
- Add post meta fields, when creating a post using WordPress’ REST API
- Store array as single, serialized post meta field or many post meta fields?