Skip to content

Instantly share code, notes, and snippets.

@zanematthew
Created June 16, 2012 15:57
Show Gist options
  • Save zanematthew/2941765 to your computer and use it in GitHub Desktop.
Save zanematthew/2941765 to your computer and use it in GitHub Desktop.
Code from the Home page controller
<?php
public function randomBanner(){
$obj_local_venues = new Tracks;
$local_venues = $obj_local_venues->getLocalVenues();
$venue_ids = array();
foreach( $local_venues as $venue ){
$venue_ids[] = $venue->ID;
}
$random_venue_id = Helpers::makeRandom( $venue_ids );
$args = array(
'post_type' => 'events',
'posts_per_page' => 1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'bmx_re_start_date',
'value' => array( date('Y-m-d'), Helpers::plusMonth(6)),
'type' => 'DATE',
'compare' => 'BETWEEN'
),
array(
'key' => 'tracks_id',
'value' => $random_venue_id,
'compare' => '='
)
)
);
$query = new WP_Query( $args );
$event = null;
if ( $query->post_count == 0 ) {
$event = false;
} else {
foreach( $query->posts as $post ){
setup_postdata( $post );
$event['title'] = $obj_local_venues->getMetaField( 'state', $random_venue_id ) . ' ' . $post->post_title;
$event['link'] = "/events/" . $post->post_name;
$event['date'] = Helpers::formatDate( $post->ID );
}
}
return $event;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment