WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm creating a public form on a page that allows non-registered (public) visitors to create posts of a custom post type.

I'm using nonces, which I naiveley thought would expire once they were used. This doesn't appear to be the case.

This post seems to address the issue by creating a meta field and verifying that it doesn't exist before creating the post.

Is there a best practice that prevents double-form submissions (that doesn't require writing a meta field?)


share|improve this question

Don't know if it's best practice but i had a similar issue and I ended up checking by custom sql query to check if the title already exists in my post type and filtered duplicate posts and i hooked that to wp_insert_post_data filter hook.

function prevente_duplicates($data,$postarr){
    $count = $wpdb->get_results($wpdb->prepare("SELECT count(id)
            FROM $wpdb->posts
            WHERE post_type = 'MY_POST_TYPE_NAME'
            AND post_title = '%s'",$data['post_title']));
    if ($count > 0 ){
        return false;
    return $data;
share|improve this answer
+ 1 for great form! This won't work in my case but only because the user is not inputting the post title. Great suggestion though. I wish WP had something built-in to handle this: seems to me it ought to. On the admin side, duplicate prevention is handled through redirects (ie: refreshing after a post has been submitted only refreshes the redirected edit page. – Tom Auger Aug 1 '11 at 3:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.