As Andreas Krischer suggested, I fixed using an script to update all the old values and then only using the wp_insert_post
to create the custom field for the new posts.
The script that I used:
INSERT INTO wp_postmeta( post_id, meta_key, meta_value )
SELECT wp_posts.ID, 'municipi', ''
FROM wp_posts
WHERE wp_posts.post_status="publish"
AND wp_posts.post_type="post"
Here I’m updating all the posts that are with the status publish and are type post, and I’m creating a custom field called municipi
with initial value empty.
Related Posts:
- Is it safe to store a user setting you don’t want the user to ever modify as a user option?
- explode array within shortcode
- Can I count the number of users matching a value in a multiple value key?
- extend Meta Box / Document Panel
- Add multiple images to a page sidebar
- getEntityRecord without knowing the post type
- How to delete custom field “suggestions” from dropdown list
- Add custom field to image editor
- How to load php file for specific page in admin?
- How to set default metaboxes on user creation?
- Metabox nonce PHP notice
- ajax jquery update custom field meta value front end
- How to break meta values into different items and avoid duplicates?
- ajax delete value from custom field array
- Add input field to ‘Pages > Edit Page’ through functions.php
- How can I query on the year part of a complete date in a custom field?
- get_post_meta not working inside loop
- WordPress Custom Field Should be Unique. Is it possible?
- How to display Meta Field Value?
- Upcoming Event: How do I sort database by custom date field, but ignore past dates?
- What is the cleanest way to extract custom variables from a post
- Add source URL from Feed WordPress (Syndication) plugin to a custom field in post editor
- Auto populate a meta box field from another meta box field when publish or save
- Conditional custom field query
- Display two custom values from a post
- Find page IDs with specific meta tag key value pairs
- Order query by meta_value with multiple custom fields
- How do I create a column in Users list and display user data from custom registration field
- Display only past events on that page using Visual Composer Grid Bulider
- user Profile meta value as custom field
- Remove Body Classes
- Send email with custom fields after new draft is saved or new post published
- Use WPbakery for own custom field [closed]
- Product Custom Fields with HTML and JS
- Get posts with same meta value as current post
- Add custom field to all posts in specific post_type
- Change the sort order for posts to include custom field
- Button inside Custom Meta Box triggering the Update Button
- query posts custom field calculation value
- Get Data From wp_sitemeta for Multisite network
- Syntax Issue: How Do I Call A Custom Field Inside a ForEach Statement? [closed]
- Get image url using image id
- Get categories query not working in function.php
- wordpress custom loop ascending descending posts by custom field
- Best filter to use for modifying custom fields on a post?
- Querying posts by latitude and longitude to build a Google Maps with several markers
- How to display childrens custom fields?
- Attach images to posts using custom fields (just paths to images already uploaded)
- how to display custom fields of post on a web page
- Changed PHP handler to DSO – weird custom fields problem [closed]
- How to fill custom fields with brackets in their key with add_post_meta()?
- Is there a way to set default custom fields when creating a new post?
- Front-End User Profile
- Add custom column for custom field
- ul list with only as many li’s as filled custom fields
- How to update user profile custom fields
- Is there a way to dump all registered sidebar/widget?
- put saved metabox values back into fields and then display on the front end
- How to hide post meta
- Custom field to array?
- How to sort by custom field value?
- Meta Box Plugin Cloned Fields – Multiple Foreach values
- get_post_meta returns 0
- How to query posts by month based on date custom field?
- Custom field bug in WordPress 3.2
- Change word in woocommerce product category custom field
- get posts based on non-single metadata
- Problem with revisions only returning four results
- How to save multiple values with same meta_key, each value linked to another tag id
- Add forms dynamically in admin pages?
- Let any visitors delete a post if they know Id nr & password?
- What WordPress “technology” would I use if I wanted subscribers to be able to mark pages with characteristics and notes?
- how can i show WordPress custom field data to my short code?
- update a custom field with the value of another existing custom field
- searching by keywords in post’s metas or pagination links problem
- Permanently show Custom Fields in Editor
- open modal window
- a lot of custom fields
- Hide custom fields by user’s role
- Ordering posts by custom fields (Date)
- update meta field value after
- PHP and Shortcode Combination
- If metabox fields has content display content
- Display Data From This Custom Media Upload Meta Box?
- Custom fields and auto save
- Save values generated via API as custom meta fields
- WP Query multiple select form – meta_query help
- update_post_meta not working in action hook
- Load code for custom fields only on admin pages?
- Custom field in a shortcode?
- Group pages by custom field values
- Exclude empty fields from custom field calculation (Average)
- How to create Parent-Child relation for custom fields?
- How to check if custom field exists in this widget query
- display loop only if a post meta data exist
- How do i output images from URL’s added to the same custom field key
- Add Custom field under the post title [closed]
- Filter Query Post by Custom Fields(by date)
- Can’t sort custom column on user.php by number / meta_value_num?
- How to apply Local Business Google Schema dynamically on a Custom Post single template?