0

I need to add a line of info to the WP post_meta array. I am wanting to place it in my child themes functions.php but I am unsure what the correct procedure is for writing an append function.

In my append function I am wanting to add in the correct data so I can fix the Google Structured Data Error: Missing required field "updated" error

1 Answer 1

0

you could use: update post meta The function update_post_meta() updates the value of an existing meta key (custom field) for the specified post.

This may be used in place of add_post_meta() function. The first thing this function will do is make sure that $meta_key already exists on $post_id. If it does not, add_post_meta($post_id, $meta_key, $meta_value) is called instead and its result is returned.

Returns meta_id if the meta doesn't exist, otherwise returns true on success and false on failure. It also returns false if the value submitted is the same as the value that is already in the database.

Please note that if your database collation is case insensitive (has with suffix _ci) then update_post_meta and delete_post_meta and get_posts will update/delete/query the meta records with keys that are upper or lower case. However get_post_meta will apparently be case sensitive due to WordPress caching.

Or add post meta Adds a custom field (also called meta-data) to a specified post which could be of any post type. A custom field is effectively a key–value pair.

Note that if the given key already exists among custom fields of the specified post, another custom field with the same key is added unless the $unique argument is set to true, in which case, no changes are made. If you want to update the value of an existing key, use the update_post_meta() function instead.

3
  • Welcome to SO. What would be the best one to use as I want to add it to all post meta no matter what the post/page ID is etc Jun 15, 2014 at 22:07
  • you need to add it in on a post id basis.. For adding post meta fileds I've had lot's of good luck with wordpress.org/plugins/types this will allow you to assign custom field groups to certain posts both custom and normal...
    – user54254
    Jun 15, 2014 at 22:53
  • Can I have an example plz - also it will allow me to answer this question :) Jun 16, 2014 at 0:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.