See Why does save_post action fire when creating a new post?
You’re getting the error as you need to check for the existence of $_POST['xxx']
, rather than just checking if $_POST
is set (it will always be set & an empty array by default).
add_action('save_post', function($id) {
if ( ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) || !isset( $_POST['xxx'] ) )
return;
update_post_meta( $id, 'xxx', sprintf( '%f', $_POST['xxx'] ) );
// run further code
});
Related Posts:
- How to show a custom meta box on the “Quick Edit” screen?
- Reset positions of metaboxes in admin
- Theme elements not translating
- Appending a value to metabox before and after saving
- How do I obtain the post content via a custom meta box inside the editor?
- More than one meta field in a single meta box?
- wp_editor() usage in custom meta box
- Is there a need for nonce with Post Metabox?
- Custom metabox for custom page template
- Custom Field created in add_meta_boxes reappearing itself again in the default Custom Metabox
- Where WordPress Stores The Custom Fields Values
- Wpautop in wp_editor not working
- How to set Post meta-box defaults based on the choices made by user in Customizer?
- Load different single.php templates according to post layout selection
- Output richtext metabox value
- show_option_none not working in meta box
- Find callback function of custom meta box
- Access meta box checked value in another file
- Create new sidebars trough admin post/page metabox
- Get all Custom Post Types
- Adding Metabox Value Using the content filter
- Support Multiple featured images
- Add custom field to existing meta box?
- How do I remove a pre-existing customizer setting?
- wp_redirect() – headers already sent
- The the_post_thumbnail without srcset?
- Enqueue Stylesheets After Theme’s “rtl.css”
- Why I can’t add a CSS style in this WordPress theme?
- Use __($str) and _e($str) to translate strings with HTML
- Posts in multiple Categories different single.php
- Custom Theme: The active theme is broken. Reverting to the default theme
- How can I stop WP media uploader from creating duplicates of my uploaded images?
- Customize comment list markup
- Have WP Theme update from Git Repository
- Help with “text domain”, comments_form in WordPress theme
- Remove “a href” from wp_list_comments()
- Get list of months with posts
- Using the theme options to change background
- How to list all images in uploads directory except those that are attached to any post
- Advanced theme training?
- Getting the wrong page ID
- Unhook action from child theme
- Does any theme support child theme?
- How do I save a wordpress theme’s files and install them on another site?
- Custom WordPress install – activate custom theme
- Media Uploader in custom path
- How to remove the header from all pages except home?
- Using AJAX in wordpress theme
- moving an admin submenu item to a top-level position
- show a post from a specific post format
- Is there any WordPress theme for Self Storagae just like Spacer [closed]
- Customizer: save setting/control content to post/page
- How do I include pre-installed images in a theme?
- Wp_customize_image_control Use Add Media
- Trackbacks not displaying
- Widget Option is Missing
- Post Content Displaying Below ALL Shortcodes Content
- If you were to start using a WordPress framework today, which one would you use? [closed]
- Register sidebar ‘before’ and ‘after’ html as div rather than li tags
- WordPress Template Part in iFrame
- Is it possible to have a theme that uses only one single page?
- JQuery undefined and Stylesheet loads in bottom along with js files
- Why tags are displayed bellow the content and not inside
- What’s the best way to create a new design for other pages?
- Consequences if using PHP include TEMPLATEPATH?
- Adding a gallery to my first theme
- Headless WordPress + Vue.js on the same server
- How to place POST TITLE any location inside the posts page
- not getting API setting saved confirmation message after update on option page
- WP_Query not getting all posts, just tagged posts
- how to hide home nav link in wordpress
- Converting a theme to a child theme in a network
- Understrap-child conditional js script
- Why excerpt hook not working inside ajax function?
- Help with Core Mods
- How can I access variables from theme in child theme? [closed]
- How to handle theme activation errors?
- Local variable name in setup_postdata()
- Child theme menu not appearing in Twenty Seventeen
- how to edit woocommerce checkout page
- WordPress Twenty-Fourteen: How to Remove Home Page Header Image from Other Pages
- Display current taxonomy slug in a post
- How to create multiple customizer controls in one control
- Setting a fluid content width
- How can I display and excerpt of all pages with a meta_key and meta_value on index.php?
- get_the_excerpt() removes all p tags in page!
- How to migrate the menu from the site on my own theme in WordPress?
- Why is including all your files within a theme folder important?
- Change default options on attachment page
- Pagination issue with Single.php
- Make theme editor to show all theme’s files
- php file child theme directory not overriding parent theme php file [duplicate]
- How do I change the tagline input to textarea?
- Creating completely new WordPress site from old WP contents
- can’t add EVENT LISTENER to a element
- add_action works outside condition but not inside it
- Should I create a child theme for a parent custom theme? [closed]
- Creating image grid on products page in wordpress
- Insert gutenberg blocks into template
- How to make it so I can “use” template parts in (classic/full) site editor