you can do that on a save_post_
hook
try that :
add_action("save_post_" . CUSTOM_POST_TYPE, function ($post_ID, \WP_Post $post, $update) {
if (!$update) {
update_post_meta($post->ID, "cx_number", "default value");
return;
}
if (isset($_POST["cx_number"])) {
update_post_meta($post->ID, "cx_number", $_POST["cx_number"]);
}
}, 10, 3);
Related Posts:
- Backup the Database and Restore from the Backup?
- Scaling a WP eCommerce site
- Looking for a lightweight theme using WP3 new tags and features (not 2010) [closed]
- Limit Media Library to Given Folder
- How can I get posts in a subcategory to display on it’s parent categories archive page?
- Creating my own Admin Forms in a WordPress CMS?
- difference between esc_attr(), strip_slashes(), strip_tags()?
- customize_register with Multiple controls/settings – how to get values?
- Best practices for A/B testing?
- Editing the Number at the end of Page URLs / Editing Page Slugs
- Integrating the WordPress admin panel with a frontend theme
- simple wp_insert_post example
- Redirect members to custom page upon logging in through WP admin
- Integrating MailChimp newsletters as post
- What is WordPress file encoding?
- WP_Query with the “offset” argument
- Adding “Interesting Tags” & “Ignored Tags” like StackOverflow.com in a WordPress Blog?
- Auto add taxonomy if post has category
- Add a containing DIV to core Gutenberg blocks
- How to Remove Subscribers from the Post Author Drop Down
- Could not create directory. /var/www/html/wp-content/plugins/PLUGIN_NAME/
- Unique User Account Number + Displayed Via Shortcode
- How can I add Google’s reCaptcha to Divi’s contact form module? [closed]
- How do I copy all “extra” data (menus, widgets, etc) from one theme to another?
- How to add more than one RSS Feed Link for wordpress
- Create default_content layout template based on post id
- Remove ability to Permanently delete an image from the Media Library
- Fatal error in wp-admin/customize.php after fresh install due to null $wp_customize
- Adding a login form that concatenates three fields into a username
- Moving from development while pulling production database without overwriting, to production
- Ability to only view (not edit) other user’s personal profile information
- Fastest way to get the comment and ping total count for a post
- Is it possible to add a ribbon in the background of h1 on every page?
- How to add textarea field to taxonomy (tag)?
- changing font size and font of a custom message added after comment
- Custom wp-content and upload directory
- Lost password empty field error redirect to custom login
- Custom comments list, right depth
- Order posts with a custom field but also without
- WordPress Custom File Permalink
- WordPress 3.0.1 on IIS 6 Web Server PermaLink Issues
- Extend WordPress Core Classes in OOP Theme?
- How To Load an HTML File As A WordPress Page (With No 301/No Redirect)
- how to display a specific wordpress menu?
- User bar above logotipo?
- Create a url structure for my blogs based on categories and sub-cats
- Can I integrate wordpress with my current website so I can utilize the wordpress plugins?
- Change Notice of Password change email subject?
- Deleting my old WordPress site. – issues
- Dynamically Filtering Posts by Data Points – Any Pointers?
- Woocommerce custom checkout form
- Remove year from title
- Custom Tags Archive – permalinks not working
- How to append custom text to the output of ‘categories widget’?
- How to assign a custom post title to be the post ID?
- Creating custom page template
- Which delete query is better with prepare or delete
- Change Site Logo or Menu Logo Per Page
- How to add page content into another page
- Remove Sidebars from page
- WP Search Form Query: Add Author’s posts into search query
- Creating a “Delete”-Button for Metadata userspecific
- Change default Video Player without Plugin
- Changing update message from Newspaper child theme
- export and import wordpress customization
- If Term Name Exists, Append a Unique ID to Slug
- where is admin footer?
- How can i add customisation of text to my theme?
- Can I overwrite custom taxonomy FROM “public” TO “false”
- Trying to customise 2011 Child Theme Background Colour
- New Page/Post Screen Opens an Existing Post
- Custom product status get filtered on all product list views
- the temporary save folder is wrong
- URL issue after setting up Custom Structure in Settings >> Permalinks
- Can I upload my self hosted WordPress website on GitHub as a project? [closed]
- Need to replace some text string on a title
- Custom roles and capabilities media not work right
- Cannot go to next page on phone but can on computer
- How to hide or remove a custom widget area when empty
- Create single{custom}.php with data in table out of wp_posts
- How do i edit text that is not in the customization menu
- Highlight specific user with custom field value
- let users add multiple divs in static page
- How do I map two domains to the same wordpress installation?
- Best way to replace image url with source
- Where should I put this custom data?
- Multiple Taxonomies Using Custom SQL Query
- Changing starting number of User ID
- how to register / add multiple options into one field in wordpress?
- Custom WP deactivate an email activation link sent to user’s email.
- How to duplicate “Pages” section in the control panel?
- WordPress Customize panel – accessing the values
- Pull certain WordPress posts on custom CMS instead and 301 wordpress to it?
- Create users via PHP
- Show post content in two different places without redirect
- Multiple Customizers
- Disable all Fonts that are Standard in WordPress and replacing them with a custom Font?
- Custom product sorting archive page
- Add custom information in editor summary
- A Voting system for a pageants