As a first step, you could create you’re own custom validation, see this topic.
The trick is then to get the code to test if that post title has already been submitted. Custom Fields are slightly different.
Take this code, put it in a php file with a unique name and upload it to your wp-content/plugins directory. It’ll create a new plugin. Once activated you’ll have a new widget called custom validation. Plonk it on the end of you’re form and voila, it wont’ allow a submission with a similar title to an existing submission (even one held in moderation).
<?php
/*
Plugin Name: My Custom Validation for TDO Mini Forms
Plugin URI: http://thedeadone.net/forum/?p=2814
Description: Blah
Version: 2
Author: Mark Cunningham
Author URI: http://thedeadone.net
*/
global $tdomf_widget_customvalidation;
function tdomf_init_widget_customvalidation() {
if(class_exists('TDOMF_Widget')) {
class TDOMF_WidgetCustomValidation extends TDOMF_Widget
{
function TDOMF_WidgetCustomValidation() {
$this->enableValidate();
// enableValidatePreview will enable validation on input on preview
$this->enableValidatePreview();
$this->setInternalName('customvalidation');
$this->setDisplayName('My Custom Validation');
$this->enableControl(false);
$this->start();
}
function validate($args,$options,$preview) {
global $wpdb;
// $preview is a boolean indicating if this is being called
// to validate a preview
// $args are the inputs from the form
extract($args);
$output = '';
// $content_title contains the inputted post title
//
$test_title = tdomf_protect_input($content_title);
// we're going to use safe_name so as to avoid mismatches with
// captials and spaces
$test_title_safe = sanitize_title($test_title);
// generate query
//
$query = "SELECT ID, post_title ";
$query .= "FROM $wpdb->posts ";
#$query .= "WHERE post_title = '$test_title' ";
$query .= "WHERE post_name = '$test_title_safe' ";
$query .= "ORDER BY ID DESC ";
$results = $wpdb->get_results( $query );
// process results (if any results we have a match)
//
if(!empty($results)) {
$output = "Sorry the title '$test_title' is very similar to an existing entry title!";
}
return $output;
}
}
}
$tdomf_widget_customvalidation = new TDOMF_WidgetCustomValidation();
}
add_action('plugins_loaded', 'tdomf_init_widget_customvalidation');
?>
How can I apply the code above if my post titles are created from custom fields submitted by visitors/users, using the code below?
$post_id, “post_title” => $post_title);
sanitize_post($postdata,”db”);
wp_update_post($postdata);
?>
I want to customize the form so that it won’t allow posts with identical titles to previous ones to be published.
Thanks,
Chris
How can I apply the code above if my post titles are created from custom fields submitted by visitors/users, using the code below?
$post_id, "post_title" => $post_title);
sanitize_post($postdata,"db");
wp_update_post($postdata);
?>
I want to customize the form so that it won’t allow posts with identical titles to previous ones to be published.
Sorry for the duplicate post but it didn’t display all the code the first time.
Thanks,
Chris
Morten
Guest
April 23rd, 2009 at 9:46 pm
Hi Robin
I’m also looking for a function there can do this on custom field like url and rss feed
Maybe this function can be used http://wordpress.org/support/topic/179920 unfortunately, just do not know how do that
Permalink | Quote