function eweek_render_extra_point() { ?> <a href="admin.php?page=eweek_index">back to eWeek</a> <h1>Club Winner</h1> <?php //code here //loop through all the participants //for each participant print out the name //form similar to check $args = array('post_type' => 'club', 'post_status' => 'published', 'posts_per_page' => -1); $clubs = array(); $the_query = new WP_Query($args); if ($the_query->have_posts()) { while ($the_query->have_posts()) { $the_query->the_post(); array_push($clubs, get_post(get_the_ID())); } } $sortedClubs = array(); foreach ($clubs as $club) { $title = $club->post_title; $id = $club->ID; $args = array('post_type' => 'eweek_participants', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array(array('key' => 'club_affiliations', 'value' => '"' . $id . '"', 'compare' => 'LIKE'))); $the_query = new WP_Query($args); // The Loop $points = 0; if ($the_query->have_posts()) { while ($the_query->have_posts()) { $the_query->the_post(); global $post; $person = get_post_meta(get_the_ID()); //if(strpos($person["club_affiliations"][0],"".$id) !== FALSE){ $points = $points + calcPointsWinner($person['events_attended'][0], $person['casino_points'][0]); //} } } $sortedClubs[$title] = $points; } arsort($sortedClubs); foreach ($sortedClubs as $title => $points) { echo $title . " : " . $points . "</br>"; } }
function winnerCallback() { $args = array('post_type' => 'eweek_participants', 'post_status' => 'publish', 'posts_per_page' => -1); $the_query = new WP_Query($args); // The Loop $points = 0; if ($the_query->have_posts()) { while ($the_query->have_posts()) { $the_query->the_post(); global $post; $person = get_post_meta(get_the_ID()); if (strpos($person['events_attended'][0], "4436") !== FALSE) { $points = $points + calcPointsWinner($person['events_attended'][0], $person['casino_points'][0]); } } } $winnerNum = rand(0, $points); wp_reset_query(); $args = array('post_type' => 'eweek_participants', 'post_status' => 'publish', 'posts_per_page' => -1); $the_query = new WP_Query($args); // The Loop $points = 0; if ($the_query->have_posts()) { while ($the_query->have_posts()) { $the_query->the_post(); global $post; $person = get_post_meta(get_the_ID()); if (strpos($person['events_attended'][0], "4436") !== FALSE) { $points = calcPointsWinner($person['events_attended'][0], $person['casino_points'][0]); $winnerNum -= $points; if ($winnerNum <= 0) { echo get_the_title() . " : " . $person['email'][0]; wp_die(); } } } } wp_die(); }