Create Event Examples

This document is intended to demonstrate how each available argument can be used when creating an event using the ORM. All examples show the required minimum arguments (title and event timing information) and the various arguments associated with that example.

To simplify things, in each example, we will use start_date and end_date for the event timing information, which uses PHP date time formatting.


Event with Cost

How to add an event that will display a cost of 15 USD price label. Note that if you use Event Tickets and later create a ticket for this event this cost will be overwritten with the ticket cost.

Example:

$args = [
	'title'             => 'Cool Event with Cost',
	'start_date'        => date( 'Y-m-d H:i:s' ),
	'end_date'          => date( 'Y-m-d H:i:s', strtotime( '+2 hours' ) ),
	'cost'              => 15,
	'currency_symbol'   => '$',
	'currency_position' => 'prefix',
];

$result = tribe_events()->set_args( $args )->create();

Top ↑

Event in a Specific Timezone

How to add an event in a different timezone than the site’s default timezone. Accepts a string that matches an option from the WordPress timezone format. If the string does not match a known option, the event’s timezone will be set to UTC.

Example:

$args = [
	'title'      => 'Conference in Paris',
	'start_date' => date( 'Y-m-d H:i:s' ),
	'end_date'   => date( 'Y-m-d H:i:s', strtotime( '+2 weeks' ) ),
	'timezone'   => 'Europe/Paris',
];

$result = tribe_events()->set_args( $args )->create();

Top ↑

Event with Description

How to add an event with a description.

Example:

$args = [
    'title'       => 'Event with Description',
    'start_date'  => date('Y-m-d H:i:s'),
    'end_date'    => date('Y-m-d H:i:s', strtotime('+3 hours')),
    'description' => 'This is showing that the description can be a long string and <h1>This Is Showing the Description</h1><b>can have HTML</b>',
];

$result = tribe_events()->set_args( $args )->create();

Top ↑

Event with Custom Slug

By default, a single event’s slug is the event title, but it can be set to something else to optimize SEO.

Example:

$args = [
	'title'      => 'Alice in Wonderland Tea Party: Becky\'s 5th Birthday',
	'start_date' => date( 'Y-m-d H:i:s' ),
	'end_date'   => date( 'Y-m-d H:i:s', strtotime( '+5 hours' ) ),
	'slug'       => 'birthday',
];

$result = tribe_events()->set_args( $args )->create();

Top ↑

Event with External Website

To create an event with a link to an external website, you can include the 'url' argument, which accepts a string. Any string entered will show on the front end as a hyperlink, though only valid URLs will function properly.

Example:

$args = [
    'title'      => 'Event with External Website',
    'start_date' => date( 'Y-m-d H:i:s', strtotime( '+1 hour' ) ),
    'end_date'   => date( 'Y-m-d H:i:s', strtotime( '+3 hours' ) ),
    'url'        => 'https://example-external-website.com',
];

$result = tribe_events()->set_args( $args )->create();

Top ↑

Event with Tags

The expected value for the'tag' argument is an array of integers or strings that correspond to the tag ID or name. If a string is in the array that is not an existing tag a new tag will be generated for that string. Strings of integers can reference existing tag IDs (i.e. 1 and '1' will both reference the tag with the ID of 1)

Example:

$args = [
    'title'      => 'Event with Tags',
    'start_date' => date( 'Y-m-d H:i:s', strtotime( '+1 hour' ) ),
    'end_date'   => date( 'Y-m-d H:i:s', strtotime( '+3 hours' ) ),
    'tag'        => [ 1, '2', 7, 'Programmatically Created Tag' ],
];

$result = tribe_events()->set_args( $args )->create();

Top ↑

Event with an Existing Category

NOTE: The  ‘publish_tribe_events’ and/or ‘edit_tribe_events’ permissions are needed in order to add an existing category when creating an event.

How to add a category when creating a new event. It’s important to note that similar to the 'tags' argument the 'category' argument accepts an array, but only of integers and strings of existing categories’ IDs. Entering a string of anything other than an existing category ID or integers that are not recognized as an existing category ID will be ignored.
Example:

$args = [
    'title'      => 'Event with Categories',
    'start_date' => date( 'Y-m-d H:i:s', strtotime( '+1 hour' ) ),
    'end_date'   => date( 'Y-m-d H:i:s', strtotime( '+3 hours' ) ),
    'status'     => 'publish',
    'category'   => [ 1, '2' ],
];

$result = tribe_events()->set_args( $args )->create();

Top ↑

Event at a Venue

Similar to categories, the value accepted for the venue argument is only an integer or string of an existing venue’s IDs. Entering a string of anything other than an existing venue ID or integers that are not recognized as an existing category ID will be ignored. The arguments 'show_map'and 'show_map_link' are also being demonstrated in this example.

Example:

$args = [
    'title'         => 'Party at a Specific Place',
    'start_date'    => date( 'Y-m-d H:i:s', strtotime( '+1 hour' ) ),
    'end_date'      => date( 'Y-m-d H:i:s', strtotime( '+3 hours' ) ),
    'venue'         => 250,
    'show_map'      => true,
    'show_map_link' => 1,
];

$result = tribe_events()->set_args( $args )->create();

If you want to create a new venue programmatically as well, you can use tribe_venues()->set_args($args)->create;– read more here.


Top ↑

Event that is Sticky

When the 'sticky' argument is set to true (or an equivalent using tribe_is_truthy()) the event will display first in the list of events that are shown within a given day block.

Example:

$args = [
    'title'      => 'Very Important Event',
    'start_date' => date( 'Y-m-d H:i:s', strtotime( '+1 hour' ) ),
    'end_date'   => date( 'Y-m-d H:i:s', strtotime( '+3 hours' ) ),
    'sticky'     => true,
];

$result = tribe_events()->set_args( $args )->create();

Top ↑

Similar to an event that you want to be ‘sticky’, making your programmatically created event a Featured Event is as simple as adding the argument 'featured' and setting it to 'true' (or an equivalent using tribe_is_truthy()).

Example:

$args = [
    'title'      => 'Featured Event',
    'start_date' => date( 'Y-m-d H:i:s', strtotime( '+1 hour' ) ),
    'end_date'   => date( 'Y-m-d H:i:s', strtotime( '+3 hours' ) ),
    'featured'   => 'yes',
];

$result = tribe_events()->set_args( $args )->create();

Top ↑

Event that is Internal

If you want to create an event that is not shown on the upcoming public calendar on the frontend, you can add the argument 'hide_from_upcoming' and set it to 'true' (or an equivalent using tribe_is_truthy()).

Example:

$args = [
    'title'              => 'Private Event',
    'start_date'         => date( 'Y-m-d H:i:s', strtotime( '+1 hour' ) ),
    'end_date'           => date( 'Y-m-d H:i:s', strtotime( '+3 hours' ) ),
    'hide_from_upcoming' => true,
];

$result = tribe_events()->set_args( $args )->create();