I recommand you to use the transition_post_status. See example below :
add_action('transition_post_status', 'wpse_110037_new_posts', 10, 3);
function wpse_110037_new_posts($new_status, $old_status, $post) {
if(
$old_status != 'publish'
&& $new_status == 'publish'
&& !empty($post->ID)
&& in_array( $post->post_type,
array( 'product')
)
) {
//add some cde here
}
}
This hook is really handy. It allows you to target a specific action: every time post data is saved. But with code I add you can avoid trigger your code if it’s a draft save or an updtate.
Related Posts:
- wordpress function to change post status [duplicate]
- Validation error: Extending Gutenberg gallery block
- Secure WordPress paid plugin
- Overriding single plugin translation
- What are some examples of well-written plugins that exemplify wordpress plugin best practices? [closed]
- Adding Image in readme.txt file of wordpress plugin
- Saving Plugin settings to the database
- How is the WordPress.org plugin download history calculated?
- $wpdb->get_results() does not fetch results with unicode ‘WHERE’ clause
- Calling shortcode in wp_localize_script strips result
- Suggestions for i18n plugin [closed]
- Autoload via composer in plugin interference
- Hide plugin list
- WP-Members redirect if member ALREADY logged in
- Can WordPress plugins “Talk to each other”?
- WordPress plugin form not saving data
- Get a list of galleries from an album in NextGEN Gallery [closed]
- wp_mail attachment not working
- Undefined property: WP_Post_Type::$ID
- Plugin exceeds memory limit
- Plugin Paths Issue
- How to remove html code in excel downloads using phpspreadsheet with wordpress plugins shortcode
- How do you export/download the file of an already-installed plugin?
- Woocommerce plugin for minimum order and add-to-card-step
- Making a plugin “Suite”?
- Automatically add attributes to woocommerce product?
- How to override a plugin function wrapped in a class?
- Load custom PHP on a custom URL via a plugin
- submit posts by unregistered users in wordpress
- WordPress Settings Lost After Site Migration
- How to put JQuery/Ajax inside shortcode?
- Programmatically Process Order through WooCommerce/Stripe Payment Gateway [closed]
- How do I get fresh post data in post_publish hook?
- WordPress Widget Not Saving Data
- How do I log out users from a restricted page if they are already logged in on another device? [closed]
- Plugin Development Form Self Submission
- How To Extend A WordPress Plugin Without Losing Your Changes [duplicate]
- WordPress call_user_func_array() expects parameter 1 to be a valid callback, class
- Why is my custom post type not being activated on plug-in activation?
- Plugins fail to update: Download failed. A valid URL was not provided
- What is the right way to show reusable content
- URLs Added to ACF Repeater Field are not working
- Where to find the code used to render a page that has a shortcode and a template defined?
- Set post tags using tag ID
- How to allow Contributors to publish articles after approval
- WordPress User Post Products
- Making my plugin create a page?
- Not One ‘Contact Form Plugin’ will send email // Work
- How to generate an all in one WordPress New content, plugin and theme update report on a website? [closed]
- How can I load the css and jquery explicitly for the login screen
- Overriding an Array in a Plugin’s Class/Function from functions.php
- Canvas | Bouncing balls within a container (with gravity and collisions and background-images on the balls)
- Plugin translation not working on WordPress.org
- Built a second plugin but it overwrote the first one
- How to get CPT category checkbox list and show post of selected(multiply) checkboxes via ajax?
- preg_replace() No ending delimiter ‘.’ found [closed]
- Preview with Custom Post Type Not Working
- How can i summerize posts or news automatically in word press site?
- Insert a Woocomerce product in specific product category
- Edit page header on a custom plugin
- How to disable tinyMCE button added by a plugin?
- Custom page in plugin visible in menu
- Remove all messages, when untrash a post
- Best method of implementing compartmentalized custom post types on a multi-site network
- How to hide the cell properties and row properties in TinyMCE WordPress?
- How to resolve warning for `unstableOnSplit` prop on a DOM element in block editor
- Rename a folder via HTML POST request
- I have English words in Kurdish pages
- How can I add a custom Javascript snippet to display my feedback in footer?
- path of wp-content directory when we are on some plugin
- Blank dashboard with no access
- How to make a page both “private” and “password protected”
- User upload dashboard
- How to duplicate a product page
- How to solve Blocked a frame with origin from accessing a cross origin frame error in wordpress?
- Add Custom Field to Post Pages via Plugin
- Timing issue with is_amp_endpoint()
- Is there a plugin to have DMCA takedown notice form in WordPress? [closed]
- Can I add content before post content without using the_content filter
- Only allow a plugin to work on a specific page? (Prefer not to use a plugin)
- hide load more button if there are no posts left to display
- Adding link for logged in user? [closed]
- Fatal Error Paid Memberships Pro require includes/localization.php [closed]
- Show image or notification on specific blog in multisite
- Child Theme Changes Are Not Reflecting In Parent Theme
- Changes required to make new plugin from existing
- WordPress Development understanding core
- Input gets deleted/overwritten after changing to different Admin Menu
- Multiple thumbnails and one gallery
- Server Path Information
- Drop down menu location select widget
- How can I allow for the password protect feature to allow visitors to enter any number at all?
- Checking url from plugin [duplicate]
- Most visited posts
- Need help finding the right plugin for a dynamic piece of content that appears multiple places
- Thumbnails and Lightbox
- Integrate Mailchimp to a Contact Form 7 contact form [closed]
- Plugin installation works only with FTP – how to debug?
- How to create a custom wordpress plugin for a specific functionality?
- Override the plugin class and function