Chris
Forum Replies Created
-
AuthorPosts
-
Hi Stiofan,
Thanks, but as I (un-clearly) said earlier, have since corrected this and the error still occurs.
Thanks Kiran,
Surely as you understand the code you must be able to give a reason why this doesn’t work, it is not a particularly complex script. All I am doing is adding one post, then another of a different type , which is being confused as the previous post type.
Also there are two bugs on the site I sent credentials across for:
1 : Image upload is not working I am getting a HTTP error (this is the manual one in the event post edit screen, also when I try an edit a post it an error is displayed).
2 : Even though the date fields are being set correctly, it displays the event start date as today on the frontend.
Would appreciate it if you could login and give these a quick look.
Thanks,
FrankHi Kiran,
Yes, i added in the global, and as you can see it is being unset both times, but it still creates a event as well as a place.
Thanks Kiren,
One last question, when I add a place after adding an event it creates a event instead of a place (or both). i presume this is something to do with the session, can you tell me how to work around this?
public function add_venue($venueid) { $venue = new SkiddleSDK\Venues; $venue->setSession($this->skiddle_session); $venue = $venue->getListing($venueid); $venue = $venue->results; pretty_export($venue); $gd_post = array(); $gd_post['post_type'] = 'gd_place'; $gd_post['status'] = 'publish'; $gd_post['title'] = isset($venue->name) ? $venue->name : ''; $gd_post['content'] = isset($venue->description) ? $venue->description : '' ; $gd_post['post_address'] = isset($venue->address) ? $venue->address: ''; $gd_post['post_country'] = ''; $gd_post['post_region'] = ''; $gd_post['post_city'] = isset($venue->town) ? $venue->town: '' ; $gd_post['post_zip'] = isset($venue->postcode) ? $venue->postcode: ''; $gd_post['post_latitude'] = isset($venue->latitude) ? $venue->latitude: ''; $gd_post['post_longitude'] = isset($venue->longitude) ? $venue->longitude: ''; $gd_post['geodir_timing'] = ''; $gd_post['geodir_contact'] = isset($venue->phone) ? $venue->link : ''; $gd_post['geodir_email'] = ''; $gd_post['geodir_website'] = isset($venue->link) ? $venue->link : '' ; $post_category = array(); $post_category[] = $venue->type; $post_tags = array(); $post_tags[] = ''; $post_images = array(); $post_images[] = $venue->imageurl; // gd_post <<< $gd_post['post_title'] = $gd_post['title']; $gd_post['post_content'] = $gd_post['content']; $gd_post['post_status'] = $gd_post['status']; $gd_post['post_images'] = ( !empty( $post_images ) ? implode( ",", $post_images ) : '' ); $cat_taxonomy = $gd_post['post_type'] . 'category'; $tag_taxonomy = $gd_post['post_type'] . '_tags'; $default_category = !empty( $post_category ) ? $post_category[0] : ''; $post_category_ids = array( ); $default_category_id = NULL; if (!get_term_by( 'name' , $post_category[0] , 'gd_placecategory' )) { wp_insert_term( $post_category[0], 'gd_placecategory'); } if ( !empty( $post_category ) ) { foreach ( $post_category as $value ) { $category_name = wp_kses_normalize_entities( trim( $value ) ); if ( $category_name != '' ) { $term_category = array(); if ( $term = get_term_by( 'name', $category_name, $cat_taxonomy ) ) { $term_category = $term; } else if ( $term = get_term_by( 'slug', $category_name, $cat_taxonomy ) ) { $term_category = $term; } if ( !empty( $term_category ) && !is_wp_error( $term_category ) ) { $post_category_ids[] = intval($term_category->term_id); if ($category_name == $default_category) { $default_category_id = intval($term_category->term_id); } } } } } $gd_post['post_default_category'] = $default_category_id; $gd_post['post_category'] = array ( $cat_taxonomy => $post_category_ids ); $gd_post[$cat_taxonomy] = $post_category_ids; $gd_post['post_tags'] = $post_tags; $gd_post[$tag_taxonomy] = $gd_post['post_tags']; if(get_page_by_title($venue->name, OBJECT, 'gd_place') || get_page_by_title($venue->name, OBJECT, 'gd_event')) return; $session_listing = !empty( $gd_session ) ? $gd_session->get( 'listing' ) : ''; if ( !empty( $session_listing ) ) { $gd_session->un_set('listing'); } $post_id = geodir_save_listing( $gd_post, null, true ); if ( !empty( $session_listing ) ) { $gd_session->set( 'listing', $session_listing ); } $my_post = array( 'ID' => $post_id, 'post_status' => 'Publish', ); wp_update_post( $my_post ); return $post_id; } public function add_event ($event) { $categories = array( 'FEST' => 'Festival', 'LIVE' => 'Live Event', 'CLUB' => 'Club', 'DATE' => 'Date', 'THEATRE' => 'Theatre', 'COMEDY' => 'Comedy', 'EXHIB' => 'Exhibit', 'BARPUB' => 'Bar / Pub', 'LGB' => 'Lesbian Gay Bi-sexual', 'ARTS' => 'Arts' ); global $wpdb, $gd_session; $startDate = strtotime($event->startdate); $endDate = strtotime($event->enddate); $startTime = strtotime($event->openingtimes->doorsopen); $endTime = strtotime($event->openingtimes->doorsclose); $venue = $event->venue; if(get_page_by_title($event->eventname, OBJECT, 'gd_event')) return; $category = $categories[$event->EventCode]; if (!get_term_by( 'name' , $category , 'gd_eventcategory' )) { wp_insert_term( $category, 'gd_eventcategory'); } $excludedIDs = explode(',', get_option( get_option('brumnotes_excluded_venues', array()))); if(in_array($venue->id , $excludedIDs) ) return; ; $gd_post = array(); $gd_post['post_type'] = 'gd_event'; $gd_post['status'] = 'publish'; $gd_post['title'] = $event->eventname ? $event->eventname : ''; $gd_post['content'] = $event->description ? $event->description : '' ; $gd_post['post_address'] = $venue->address ? $venue->address: ''; $gd_post['post_country'] = $venue->country ? $venue->country: ''; $gd_post['post_region'] = $venue->postcode_lookup ? $venue->postcode_lookup: ''; $gd_post['post_city'] = $venue->town ? $venue->town: '' ; $gd_post['post_zip'] = $venue->postcode ? $venue->postcode: ''; $gd_post['post_latitude'] = $venue->latitude ? $venue->latitude: ''; $gd_post['post_longitude'] = $venue->longitude ? $venue->longitude: ''; $gd_post['geodir_timing'] = ''; $gd_post['geodir_contact'] = $venue->phone; $gd_post['geodir_email'] = ''; $gd_post['geodir_website'] = $event->link . '?sktag=12752'; $gd_post['geodir_event_price'] = $event->entryprice; $gd_post['geodir_venue_name'] = $venue->name; $gd_post['is_recurring'] = '0'; $gd_post['all_day'] = '0'; $gd_post['event_start'] = date('F j, Y', $startDate); $gd_post['event_end'] = date('F j, Y', $endDate); $gd_post['starttime'] = date('G:i A', $startDate); $gd_post['endtime'] = date('G:i A', $endDate); $post_category = array($category); $post_category[] = 'Events'; $post_tags = array(); $post_images = array(); $post_images[] = $event->largeimageurl; // gd_post <<< $gd_post['post_title'] = $gd_post['title']; $gd_post['post_content'] = $gd_post['content']; $gd_post['post_status'] = $gd_post['status']; $gd_post['post_images'] = ( !empty( $post_images ) ? implode( ",", $post_images ) : '' ); $cat_taxonomy = $gd_post['post_type'] . 'category'; $tag_taxonomy = $gd_post['post_type'] . '_tags'; $default_category = !empty( $post_category ) ? $post_category[0] : ''; $post_category_ids = array( ); $default_category_id = NULL; if ( !empty( $post_category ) ) { foreach ( $post_category as $value ) { $category_name = wp_kses_normalize_entities( trim( $value ) ); if ( $category_name != '' ) { $term_category = array(); if ( $term = get_term_by( 'name', $category_name, $cat_taxonomy ) ) { $term_category = $term; } else if ( $term = get_term_by( 'slug', $category_name, $cat_taxonomy ) ) { $term_category = $term; } if ( !empty( $term_category ) && !is_wp_error( $term_category ) ) { $post_category_ids[] = intval($term_category->term_id); if ($category_name == $default_category) { $default_category_id = intval($term_category->term_id); } } } } } $gd_post['post_default_category'] = $default_category_id; $gd_post['post_category'] = array ( $cat_taxonomy => $post_category_ids ); $gd_post[$cat_taxonomy] = $post_category_ids; $gd_post['post_tags'] = $post_tags; $gd_post[$tag_taxonomy] = $gd_post['post_tags']; $session_listing = !empty( $gd_session ) ? $gd_session->get( 'listing' ) : ''; if ( !empty( $session_listing ) ) { $gd_session->un_set('listing'); } $post_id = geodir_save_listing( $gd_post, null, true ); if ( !empty( $session_listing ) ) { $gd_session->set( 'listing', $session_listing ); } $my_post = array( 'ID' => $post_id, 'post_status' => 'Publish', ); wp_update_post( $my_post ); $this->add_venue($venue->id); return $post_id; }
Thanks Alex,
Is this easy to add?
Hi Guys,
Thanks for all of your help with this.
One more question, how can I link a place to the event in the post object>
Hi Kiren,
Image upload is fixed, turned out to be a bug with WordPres,s which was solved by updating…
Could you let me know why the posts are pending and how I can set them to publish?
Hi Kiren,
Could you try that URL and see if it works on your setup?
Also using your function, the posts are set to status pending, could you tell me why that is?
Here is an example URL : https://d31fr2pwly4c4s.cloudfront.net/6/f/8/993883_1_sutton-vintage-arts-fair-_th.jpg
Hi kiren,
Sorry, I don’t mean to sound rude, I really need to get this working for a client.
Manually entering the image URL also does not work, which means I need override the check.
Are you using the WP Importer plugin and could we alter the code to skip verifying the file?
Or Could we just reference the external url without uploading?
Hi kiren,
Apologies, I am now using your full code and the DB is working fine.
Though the error has returned :
Array ( [errors] => Array ( [import_file_error] => Array ( [0] => Remote file is incorrect size ) ) [error_data] => Array ( ) ) .
This as I already mentioned is discussed here : https://codeboxr.com/fix-remote-file-is-incorrect-size-for-wordpress-import-error/
Are you using the WP Importer plugin and could we alter the code to skip verifying the file?
Full code :
Aglobal $wpdb, $gd_session; $startDate = strtotime($event->startdate); $endDate = strtotime($event->enddate); $startTime = strtotime($event->openingtimes->doorsopen); $endTime = strtotime($event->openingtimes->doorsclose); $venue = $event->venue; $gd_post = array(); $gd_post['post_type'] = 'gd_event'; $gd_post['status'] = 'publish'; $gd_post['title'] = $event->eventname; $gd_post['content'] = $event->description; $gd_post['post_address'] = ''; $gd_post['post_country'] = $venue->country; $gd_post['post_region'] = $venue->postcode_lookup; $gd_post['post_city'] = $venue->town; $gd_post['post_zip'] = $venue->postcode; $gd_post['post_latitude'] = $venue->latitude; $gd_post['post_longitude'] = $venue->longitude; $gd_post['geodir_timing'] = ''; $gd_post['geodir_contact'] = $venue->phone; $gd_post['geodir_email'] = '[email protected]'; $gd_post['geodir_website'] = $event->link . 'afilate'; $gd_post['is_recurring'] = '0'; $gd_post['all_day'] = '0'; $gd_post['event_start'] = date('F j, Y', $startDate); $gd_post['event_end'] = date('F j, Y', $endDate); $gd_post['starttime'] = date('G:i A', $startDate); $gd_post['endtime'] = date('G:i A', $endDate); $post_category = array(); $post_category[] = 'Events'; $post_tags = array(); $post_tags[] = 'feed festival'; $post_images = array(); $post_images[] = $event->imageurl; // gd_post <<< $gd_post['post_title'] = $gd_post['title']; $gd_post['post_content'] = $gd_post['content']; $gd_post['post_status'] = $gd_post['status']; $gd_post['post_images'] = ( !empty( $post_images ) ? implode( ",", $post_images ) : '' ); $cat_taxonomy = $gd_post['post_type'] . 'category'; $tag_taxonomy = $gd_post['post_type'] . '_tags'; $default_category = !empty( $post_category ) ? $post_category[0] : ''; $post_category_ids = array(); $default_category_id = NULL; if ( !empty( $post_category ) ) { foreach ( $post_category as $value ) { $category_name = wp_kses_normalize_entities( trim( $value ) ); if ( $category_name != '' ) { $term_category = array(); if ( $term = get_term_by( 'name', $category_name, $cat_taxonomy ) ) { $term_category = $term; } else if ( $term = get_term_by( 'slug', $category_name, $cat_taxonomy ) ) { $term_category = $term; } if ( !empty( $term_category ) && !is_wp_error( $term_category ) ) { $post_category_ids[] = intval($term_category->term_id); if ($category_name == $default_category) { $default_category_id = intval($term_category->term_id); } } } } } $gd_post['post_default_category'] = $default_category_id; $gd_post['post_category'] = array ( $cat_taxonomy => $post_category_ids ); $gd_post[$cat_taxonomy] = $post_category_ids; $gd_post['post_tags'] = $post_tags; $gd_post[$tag_taxonomy] = $gd_post['post_tags']; if(get_page_by_title($event->eventname, OBJECT, 'gd_event')) return; $session_listing = !empty( $gd_session ) ? $gd_session->get( 'listing' ) : ''; if ( !empty( $session_listing ) ) { $gd_session->un_set('listing'); } $post_id = geodir_save_listing( $gd_post, null, true ); if ( !empty( $session_listing ) ) { $gd_session->set( 'listing', $session_listing ); } return $post_id;
Hi Kiren,
Thanks I did not realize it would work without uploading the image first.
However when I remove the file uploa, and set
geodir_save_listing($post_info, null, true );
I am getting the follow errors:
WordPress database error: [Table 'brumnote_wpdb_st1.wp_geodir_post_detail' doesn't exist] show columns from wp_geodir_post_detail WordPress database error: [Table 'brumnote_wpdb_st1.wp_geodir_post_detail' doesn't exist] show columns from wp_geodir_post_detail WordPress database error: [Table 'brumnote_wpdb_st1.wp_geodir_post_detail' doesn't exist] UPDATE wp_geodir_post_detail SET featured_image = '' where post_id =21112 Array ( [errors] => Array ( [import_file_error] => Array ( [0] => Remote file is incorrect size ) ) [error_data] => Array ( ) )
Could you explain why this table is missing?
Would it be possible to set the images to external URLS after the post has been created?
OK,
I am now uploading the image and adding the media library :
public function add_event ($event) {
$startDate = strtotime($event->startdate);
$endDate = strtotime($event->enddate);
$startTime = strtotime($event->openingtimes->doorsopen);
$endTime = strtotime($event->openingtimes->doorsclose);
$venue = $event->venue;// Get the path to the upload directory.
$wp_upload_dir = wp_upload_dir();$imgname = basename($event->imageurl);
$uploadpath = $wp_upload_dir[‘path’] . ‘/’ . $imgname ;
$uploadurl = $wp_upload_dir[‘url’] . ‘/’ . $imgname ;
if(!file_exists( $uploadpath)) {
if(copy($event->imageurl,$uploadpath)) {$attachment = array(
‘guid’=> $uploadurl,
‘post_mime_type’ => ‘image/png’,
‘post_title’ => ‘my description’,
‘post_content’ => ‘my description’,
‘post_status’ => ‘inherit’
);$image_id = wp_insert_attachment($attachment, $uploadpath);
// Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
require_once( ABSPATH . ‘wp-admin/includes/image.php’ );// Generate the metadata for the attachment, and update the database record.
$attach_data = wp_generate_attachment_metadata( $image_id, $uploadpath );wp_update_attachment_metadata( $image_id, $attach_data );
}
}
$post_images = array($imgname);
$post_info = array();
$post_info[“listing_type”] = ‘gd_event’;
$post_info[“post_title”] = $event->eventname;
$post_info[“post_desc”] = $event->description;
$post_info[‘status’] = ‘publish’;
$post_info[“post_images”] = ( !empty( $post_images ) ? implode( “,”, $post_images ) : ” );;
$post_info[“post_category”] = array(‘gd_eventcategory’ , array(‘Events’));
$post_info[“post_tags”] = array(”);
$post_info[“geodir_video”] = ”;
$post_info[“geodir_contact”] = $venue->phone;
$post_info[“geodir_website”] = $event->link . ‘afilate’;
$post_info[“starttime”] = date(‘G:i A’, $startDate);
$post_info[“endtime”] = date(‘G:i A’, $endDate);
$post_info[‘post_city’] =$venue->town;
$post_info[‘post_region’] =$venue->postcode_lookup;
$post_info[‘post_country’] =$venue->country;
$post_info[‘post_zip’] = $venue->postcode;
$post_info[‘post_latitude’] = $venue->latitude;
$post_info[‘post_longitude’] = $venue->longitude;
$post_info[“event_start”] = date(‘F j, Y’, $startDate);
$post_info[“event_end”] = date(‘F j, Y’, $endDate);
$post_info[‘is_recurring’] = 0;pretty_export($post_info);
if(get_page_by_title($event->eventname, OBJECT, ‘gd_event’)) return;
geodir_save_listing($post_info, true );
}This has stopped the original error, but the image is not added to the post.
Can you explain why?
ALso where do I find the geodir_save_listing() function in the main source?
-
AuthorPosts