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:
- Best collection of code for your 'functions.php' file [closed]
- Using WordPress as a CMS: Developer preferences for custom vs existing plugins
- is_plugin_active() returning false on active plugin
- Unable to check if plugin is active
- Preserve custom URL parameter on more pages
- Sort plugins by rating
- How to Delete All regenerated thumbnails but keep the original ones?
- Why do I get this “plugin does not have a valid header” error?
- if plugin is active? check if plugin is enabled or not?
- WordPress Capabilities: edit_user vs edit_users
- Passing .pem and .key files in cURL doesn’t work in WordPress
- Is there a limit on the size of a WP page?
- A Blog’s changelog
- Adding a widget programmatically
- How do I create a custom wordpress slideshow plugin?
- Updating a WordPress plugins breaks SVN
- Seeking clarification on page request life-cycle
- Modify the_content after the more tag
- Template plugin for blog posts? [closed]
- Offering Ads Dependent on Visitor Type?
- Licensing of freemium plugin
- Can I store WordPress media in different sub-folders?
- AddFilter option_active_plugins is executed 6 times. Why?
- Include Max mega menu Plugin into theme
- Default Plugin Settings Not Writing to Database
- Create a custom page template inside my wordpress plugin
- Add form fields dynamically on button click
- Custom Post Type Plugin not loading category template and loading 404 instead
- WP plugins for building a database?
- Change the method of a class from child function.php
- Can I use a plugin for a singular page on my website?
- Create digital-virtual-downloadable WooCommerce products from the frontend using Gravity Forms? [closed]
- Is it possible to add a sidebar in a woocommerce hook?
- How to add Internationalization in WordPress using Javascript/React?
- How to send an automated email to the customers when product is added woocommerce
- Trying to Get Text Field to Save
- creating html reusable blocks via shortcodes
- I want to auto populate data in three fields if one drop down is selected
- How to insert HTML/JavaScript form into WordPress page? [closed]
- How to change upload dir for custom plugin?
- Creating a CSV with PHP inside the plugin directory
- pagination on data fetched using SQL query
- How do I automatically generate pages from a database?
- WordPress plugin won’t show on some themes
- Is there a plugin for WordPress for creating ‘Accounts’ where all users who belong to that Account can only see Account data? [closed]
- wp_redirect doen’t work
- Send email with list of active plugins upon activation/deactivation
- How to save plugin custom settings page fields
- wp_insert_term() doesnt insert a term
- How limit user connection?
- Memory Management when developing plug-ins
- How can I list custom post type categories of portfolio
- How to include my Ajax calls in one function instead of calling different ones every time?
- How to add img into a plugin?
- How to log custom plugin error to debug.log file
- Using AJAX to run SQL statement and populate dropdown
- wp_footer hook running twice
- Strange admin-ajax / CSS / $_SESSION issue
- How to create admin setting for this small plugin
- How to create a form where you can select multiple recipients, based on a list of website users?
- Unpublished Pages Failing To Appear On Custom Path
- $wpdb->delete not working for me
- How to fix caching issue in PHP data from database
- WPForms Custom Redirect not working
- Lock content in WordPress website
- How do I allow a user to purchase an expiring passcode to access part of my website, from my online store, similar to pay-per-view?
- How to securely controlling data without keeping it in postmeta?
- Enqueue plugin for specific pages
- Why Custom fields description is not working WordPress Version 5.4.2?
- Get Current Post ID in WP Loop For GiveWP
- Does having apply_filters in the middle of an array make a difference?
- URL path image error in ACF (Advanced Custom Field) [closed]
- Problem Advanced Custom Fields PRO
- Unable to activate themes on localhost
- Soflyy WP All Import Custom File Download Issue
- Unmatch plugin from updates?
- Identify if the_post hook is being called from the admin post list
- why my wordpress dont have toolbar like, plugin, themes and other?
- Reorganization of namespaces
- Why can’t I shove an instance of a class into a variable from a do_action hook?
- Passing a parameter to filter and action functions
- Custom pages with plugin
- How to insert category name above post title in a featured pages plugin?
- Plugin Installation Error
- How to add submenu to WordPress plugin in the same Directory of main Plugin?
- Holding 2 wp_user in the same action (to update billing_email when user_email is updated)
- Strange get_the_* behavior with php 5.4
- How to set-up multiple cron task with wp_schedule_event so that they do not overlap?
- 404 Page when emptying spam or deleting a plugin
- File permissions for wp-minify plugin
- Ajax not working for logged in users
- How to declare this function correctly?
- How to show in front End images using Visual Composer attach_images?
- Plugin version number after code rewrite [closed]
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- Update Content for a Custom Block Toolbar Button
- Issue with customizer and widget page
- Submitting form to admin-post.php WordPress
- WordPress Throwing Deprecated Errors on its own Files
- How to update a lot of posts on my WP site with additional content?