Which hook do I use for the following scenarios?
-
Hi,
I am writing a plugin for my own site which allows user submitted content to a custom post type with custom fields.
I want to check for duplicates and have looked at two ways to do this.
1 – Run when a post is saved, to see if there is a duplicate in my post_meta table, if there is return false for wp_insert_post_data
however when I do this, it returns to the add post page for the custom post type with an error but still saves some data
2 – Save the post and once saved check for the duplicate and then delete the post and inform user of duplicate.
I can’t seem to find which action hook I would use for scenario 2.
Save_post wants a post id or post data, and I can’t see just how to use this.
My function should be very simple along the lines of
if ($post_type == 'media_link') { $query = "SELECT count(ID) FROM {$wpdb->prefix}media_links WHERE LOWER(link)='".strtolower($_POST["cctm_media_link"])."' and "; $count = $wpdb->get_var($query); if ($count > 1 ){ echo "there is a duplicate"; } else { echo "there are no duplicates"; } return $data;
So really I just need to run that query to see if there are other items, if there are then I need to do something with that like wp_delete()
also once I run the delete, how do I return a message to the user telling them that it was a duplicate?
Dan
- The topic ‘Which hook do I use for the following scenarios?’ is closed to new replies.