Tell us what you are trying to do?
Prevent titles in CRED post forms from being added if published or pending based on title.
The code was working, but recently I've noticed that movie titles are not working as expected. Recently I added a title "xxxHOLiC" and this was not in the list of published or pending, but the error keeps showing up. As a result I have to rename the title and then it'll save. Then I have to go back and edit and save again.
Is there any documentation that you are following?
Waqar helped me previously in this thread: https://toolset.com/forums/topic/prevent-duplicate-post-titles-from-being-created/page/2/
Is there a similar example that we can see?
Code used:
/* Toolset: Validate CRED Forms for Dupe Titles */
add_filter('cred_form_validate','func_validate_title',10,2);
function func_validate_title($error_fields, $form_data){
list($fields,$errors)=$error_fields;
$forms_array = array( 33531, 33564, 33555, 33560, 33535 );
if (in_array($form_data['id'], $forms_array)) {
// get the title from the form
$title = $_POST['post_title'];
// query to get the posts to compare
$args = array( "post_type" => array('drama', 'movie', 'special', 'person', 'fansubber'), "posts_per_page" => -1, "post_status" => array('publish', 'pending') );
$query = get_posts( $args );
if (count($query) > 0){
//set error message for the title field if a post of the same title exists
foreach ($query as $post) {
if (strtolower($post->post_title) == strtolower($title)) {
$errors['post_title']='This title already exists!';
break;
}
}
}
}
//return result
return array($fields,$errors);
}
What is the link to your site?
hidden link (this is only available for registered users)