(Solved) How can I set a pre-defined venue via php?

Home Forums Calendar Products Events Calendar PRO (Solved) How can I set a pre-defined venue via php?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #102684
    efromdc
    Participant

    Im doing the following to import some data from a csv file via php:

    $venueData = array();
    $venueData[‘Venue’] = venuename
    $venueData[‘post_type’] = ‘tribe_venue’;
    $venueData[‘Country’] = country;
    $venueData[‘Address’] = address;
    $venueData[‘City’] = city;
    $venueData[‘State’] = state;
    $venueData[‘Zip’] = zip;
    $venueData[‘ShowMap’] = true;
    $venueData[‘ShowMapLink’] = true;
    $venueData[‘Phone’] = phone;
    $venueData[‘URL’] = url;
    $event[‘Venue’]=$venueData;
    $event[‘post_title’] = Title;
    $event[‘post_status’] = ‘pending’;
    $event[‘post_type’] = ‘tribe_events’;
    $event[‘post_author’] = $postAuthor;
    $event[‘post_content’] = $postBody;
    $event[‘EventStartDate’] = date(“Y-m-d H:i:s”, now());
    $event[‘EventEndDate’] = date(“Y-m-d H:i:s”, ‘+1 day’);
    $event[‘EventShowMapLink’] = true;
    $event[‘EventShowMap’] = true;

    $postID = tribe_create_event($event);

    This works fine (I might have an error in the code above as I wrote this off the top of my head, but you get the point).

    1. How do I test to see if a venue already exists in my db? For example, if the venue name in the csv is “my place” but I already have “my place” defined in the database, I dont want to create a second instance. I want to use the one thats already there

    2. If I already have it defined, how can I set the params above to use THAT venue name / id instead of defining it like above?
    Thanks!

    #103231
    Barry
    Member

    Hi, great questions!

    For the first issue (of detecting an existing venue with a given name), perhaps you could simply achieve this with a custom query? A successful result will yield the post ID. For the second issue, the following information might clarify things:

    Note: If ONLY the ‘VenueID’/’OrganizerID’ value is set in the ‘Venue’/’Organizer’ array, then the specified Venue/Organizer will be associated with this Event without attempting to edit the Venue/Organizer. If NO ‘VenueID’/’OrganizerID’ is passed, but other Venue/Organizer data is passed, then a new Venue/Organizer will be created.

    Does that help?

    #104444
    efromdc
    Participant

    I actually implemented this a few hours before you replied:

    $venueQuery = get_page_by_title( $venue, OBJECT, ‘tribe_venue’ );
    if ($venueQuery) {
    update_post_meta( $postID, ‘_EventVenueID’, $venueQuery->ID; );
    }
    else {
    $venueData = array();
    $venueData[‘Venue’] = $name
    $venueData[‘post_type’] = ‘tribe_venue’;
    $venueData[‘Country’] = $country;
    $venueData[‘Address’] = $street;
    $venueData[‘City’] = $city;
    $venueData[‘State’] = $state;
    $venueData[‘Zip’] = $zip;
    $venueData[‘ShowMap’] = true;
    $venueData[‘ShowMapLink’] = true;
    $venueData[‘Phone’] = $phone;
    $venueData[‘URL’] = $url;
    $event[‘Venue’]=$venueData;

    #104767
    Barry
    Member

    Excellent!

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘(Solved) How can I set a pre-defined venue via php?’ is closed to new replies.