Read the rest of this page »'); ?>
posts wposts
LEFT JOIN $wpdb->postmeta wpostmeta ON wposts.ID = wpostmeta.post_id
LEFT JOIN $wpdb->term_relationships ON (wposts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
WHERE wposts.post_status = 'publish'
AND wposts.post_title = '$title'
AND wposts.post_content = '$content'
AND $wpdb->term_taxonomy.taxonomy = 'category'
AND $wpdb->term_taxonomy.term_id IN($categorie)";
$verifica = $wpdb->get_results($sql);
if( 'POST' == $_SERVER['REQUEST_METHOD'] ) { // if form has been submitted
# some validation
if(empty($title)) {
echo "Please give your post a title
";
}
if (empty($content)){
echo "Please write your post's content
";
}
if ($categorie == -1){
echo "Please assign a category to your post.
";
}
# if there are no similar posts ($verifica is empty) and user filled in the fields, insert post
# also, redirect to the homepage to make sure we don't get 404-ed
if (empty($verifica) && !empty($title) && !empty($content) && $categorie != -1) {
$my_post = array(
'post_title' => $title,
'post_excerpt' => $content,
'post_status' => 'draft',
'post_author' => 1,
'tax_input' => array( 'fayre-region' => $categorie ),
'post_type' => 'fayres'
);
$my_post = wp_insert_post($my_post);
add_post_meta($my_post, 'venue_name', $venue);
add_post_meta($my_post, 'fayre_date', $countdowndate);
add_post_meta($my_post, 'fayre_start_time', $starttime);
add_post_meta($my_post, 'fayre_end_time', $endtime);
add_post_meta($my_post, 'entry_fee', $entry);
add_post_meta($my_post, 'link', $link);
add_post_meta($my_post, 'venue_address', $address);
add_post_meta($my_post, 'contact_name', $contact);
add_post_meta($my_post, 'contact_number', $phone);
add_post_meta($my_post, 'contact_email', $email);
if (!function_exists('wp_generate_attachment_metadata')){
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
}
if ($_FILES) {
foreach ($_FILES as $file => $array) {
if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) {
return "upload error : " . $_FILES[$file]['error'];
}
$attach_id = media_handle_upload( $file, $my_post );
}
}
if ($attach_id > 0){
//and if you want to set that image as Post then use:
update_post_meta($my_post,'_thumbnail_id',$attach_id);
}
wp_redirect( home_url() );
}
# if $verifica is not empty, then we don't insert the post and we display a message
else if( !empty($verifica) ) { echo "You are trying to submit the same post twice! Be nice."; }
}
?>