Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created April 9, 2019 12:38
Show Gist options
  • Save tommcfarlin/24e5bae859863d39512abc2af2169fbb to your computer and use it in GitHub Desktop.
Save tommcfarlin/24e5bae859863d39512abc2af2169fbb to your computer and use it in GitHub Desktop.
<?php
/**
* Retrieves the title of the Event, a custom post type.
*
* @param int $eventId the ID of the event post type
* @return string the title of the post.
*/
public function getName(int $eventId): string
{
return get_the_title($eventId);
}
<?php
/**
* A helper function for easily retrieving post meta data for a given Event.
*
* @param int $id the ID of the event
* @param string $key the key for the post meta data for which we're retrieveing the data
*
* @return string the result of retrieiving the meta data
*/
private function get(int $id, string $key): string
{
return get_post_meta($id, $key, true);
}
<?php
/**
* @param int $eventID the ID of the event
* @return string the name of the event of an empty string
*/
public function getLocationName($eventId): string
{
return $this->get($eventId, 'ymc-event-location-name');
}
<?php
/**
* @return string the URL to the event next to the current event.
*/
public function getNextEventUrl()
{
global $wpdb;
$results = $wpdb->get_results(
$wpdb->prepare(
"
SELECT *
FROM $wpdb->posts
WHERE ID > (
SELECT ID
FROM $wpdb->posts
WHERE ID = %d
AND post_type = '%s'
AND post_status = '%s'
ORDER BY ID ASC
)
AND post_type = '%s'
AND post_status = '%s'
ORDER BY ID ASC
LIMIT 1
",
get_the_ID(),
'ymc-events',
'publish',
'ymc-events',
'publish'
)
);
$result = (isset($result[0])) ? $result[0] : '';
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment