Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chancecorbeil/4acc0e80ba07365eb735726597dfefd1 to your computer and use it in GitHub Desktop.
Save chancecorbeil/4acc0e80ba07365eb735726597dfefd1 to your computer and use it in GitHub Desktop.
function tcp_list_timetable_route_ids( $args = array() ) {
if ( ! post_type_exists('route') ) {
// Fail silently
return;
}
$defaults = array(
'before' => '<div class="tcp_route_list">',
'after' => '</div>',
'sep' => ' ',
'use_color' => false, // TODO - doesn't work
'show_circle' => false,
'route_name' => 'long_name',
'show_alert' => false, // TODO - doesn't work
'alert_markup' => 'default',
);
$args = wp_parse_args( $args, $defaults );
// Returns a sorted array of timetable objects.
function tcp_get_timetables() {
if ( ! post_type_exists( 'timetable') ) {
// Fail silently
return;
}
// timetable sort
$timetable_args = array(
'post_type' => 'timetable',
'numberposts' => -1,
'orderby' => 'ASC',
);
return get_posts( $timetable_args );
}
$timetable_posts = tcp_get_timetables();
$timetables = array();
// Format and output each timetable in the database
foreach ( $timetable_posts as $timetable ) {
// Add formatted timetable link to an array
$timetables[] = '<a href="' . get_the_permalink($timetable->ID) . '" class="' . $timetable->post_name . '">' . $timetable->route_id . '</a>';
}
echo $args['before'] . join( $args['sep'], $timetables ) . $args['after'];
}
tcp_list_timetable_route_ids();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment