Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?)

T

share|improve this question
add comment

1 Answer 1

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.

add_filter('wp_insert_post_data','prevente_duplicates');
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
add comment

Your Answer

 
discard

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.