The ‘wp_insert_post’ action is fired for each post that is inserted and passed the ID of the inserted post to the callback function, so I think your $wpdb query is unnecessary – in fact, I think you’re running the “custom function” portion for all published posts, not just the inserted post (which may or may not lead to issues depending on what you’re actually doing).
function on_post_import( $post_id ) {
// custom function using $post_id
}
add_action( 'wp_insert_post', 'on_post_import' );
Related Posts:
- Get posts from WP_Query and format them on admin_head
- How to insert multiple postmeta values with one query?
- any word search WordPress
- How to fix slow comment query?
- WooCommerce shop page orderby [closed]
- WordPress filter that hook after each action/filter hook
- How to stop or remove an action being called inside a function of an extended class
- Automatically add attributes to woocommerce product?
- Not getting author rank when using return
- Doubt using $wpbd->get_col for a single column
- Any hook for pre-plugin-update -either bulk or single plugin update
- How to query the custom fields by language?
- Access WordPress database outside of WordPress
- How do I “get the next 10 posts after post_id == x”?
- wordpress plugin is not activating from widget
- Insert new user with form submit ‘init’ hook
- Correct way to perform non-cacheable DB query
- switched from query_posts to WP_query, not working now?
- Help With MySQL to WPDB Query Conversion
- When to load auto-login code?
- AJAX search posts and pages
- How to get all of the activate_plugin action parameters?
- How to use wordpress $polylang->model->set_post_language in custom php code?
- Creating mySQL procedure with $wpdb
- DROP TABLE with uninstall hook not working
- Problem with creating tables for Plugin
- Calling plugin function inside custom plugin for onclick event
- How to change this WP_Query to get all ProductIDs and not only specific one?
- How to check current user before all actions and filters?
- Change commission_status paid when withdraw_status vendor is completed
- CampaignMonitor for WooCommerce – Move subscribe button [closed]
- Get Time Taken By Each Action Hook in WordPress
- Are functions in main plugin file called before function bound to register_activation_hook runs?
- How to call WordPress function other files
- Removing an action from wp_footer called in a class that’s inside a bigger class
- Insert content of a post into another
- Plugin developer automated documentation
- Custom plugin init action causing general slowness
- Is there a hook to Intercept al urls from a webpage and redirect to a page
- WP_Query and NULL meta keys
- $wpdb->get_row returns column name instead of column value
- add_action in static class [closed]
- how to use in custom single.php template using php?
- WordPress user account activation
- Create a table with wordpress plugin boilerplate
- WordPress page and plugin list using sql query
- How to create a custom shortcode based on the layout?
- Using AJAX to generate front end / viewer end pages
- External Script Using WP – Hooks / Actions Not Working?
- Submit custom form from post content and execute in plugin
- plugin code is pulling information from database in one instance and not in other. What is wrong?
- Inject HTML meta tag inside wordpress tag using add_shortcode
- Object method calling for global $wpdb in header.php
- How to get post ID with hooks publish_post, new_to_publish, etc
- add_action in a custom plugin
- WooCommerce search products between price range using WP_Query
- Using wpdb without loading all plug-ins via wp-load.php
- ACF: post query, hide duplicate values [closed]
- register_activation_hook in oop approach
- Redirect to another page using contact form 7? [closed]
- What is @Action in WordPress?
- Problem with removing plugin action
- edit_user_profile and show_user_profile are not firing inside a class
- Add action to fire when a published post is updated
- do add_action on condition
- Is there a way to figure out which action/filter invoked a function?
- get gravity form ID from backend/wordpress admin
- How to pass variables to a function argument using add_action [duplicate]
- _prime_post_caches in wordpress
- How to trace SUBMIT button
- How passing values to construct function with Actions?
- Remove_action from plugin with a Class
- add_action into another add_action not working
- after wordpress update to 3.5+ i get many errors in plugin wpdb::prepare()
- publish_post action doesn’t work
- Run a plugin just ‘once’ per page reload
- Using add_action before add_filter on a plugin?
- Cannot get wpdb data (Error in a simple fuction) [closed]
- WPDB: Update table
- How to Loop Through all Posts and Count Attachments using Get Media Attachments
- Issue running db create table query from static method
- a weird attribute on every html tag
- Submit Form data to another page via Ajax (WordPress Way)
- the_post hook is not firing for me
- $wpdb update query in plugin only updating one column
- Why do plugins often ask to add in to templates?
- Does using `add_action( ‘init’…` cause performance issues?
- do_action Nested List
- How to get a list of bundled products using wp_query in woocommerce
- order posts by `meta_key`, Does not display posts that does not have `meta_key`
- Create a post builder skin in a plugin
- remove_action not removing add_action from constructor
- Plugin Development – Functions or Hooks?
- WordPress Apply filter in plugin causes 500 internal error
- Meta query for comparing two dates
- How to get menu location in wp_update_nav_menu hook
- How do I add some javascript validation to the admin interface form’s onsubmit?
- Basic function call on init failing
- Create WordPress posts from JSON array using plugin in admin
- How to create Admin Notice from Plugin with argument? [duplicate]