prefix . “posts”;
$postmetatable = $wpdb->prefix . “postmeta”;
$result = $wpdb->get_results ( ”
SELECT *
FROM $wpdb->posts p
WHERE p.post_type = ‘feedback’ and post_status = ‘publish’ and p.post_date > ‘2018’
order by p.post_date
” );
$aresult = array();
$aresult_single = array();
$aresult_singled = array();
if (! $result) {
$Error = $wpdb->print_error();
die(“The following error was found: $Error”);
} else {
foreach ( $result as $page )
{
//echo ‘ID:’.$page->ID.’ ‘.$page->post_title.’ ‘.$page->meta_key.’
‘;
$content = $page->post_content;
$pmetass = “SELECT meta_value FROM `wp_udwkt4_postmeta` WHERE post_id = ‘$page->ID’ and meta_key = ‘_feedback_extra_fields'”;
$pmetaem = “SELECT meta_value FROM `wp_udwkt4_postmeta` WHERE post_id = ‘$page->ID’ and meta_key = ‘_feedback_email'”;
$pmetaakis = “SELECT meta_value FROM `wp_udwkt4_postmeta` WHERE post_id = ‘$page->ID’ and meta_key = ‘_feedback_akismet_values'”;
$pmeta = $wpdb->get_var($pmetass);
$extraf = unserialize($pmeta);
$thename = shittyarray($content, ‘[1_Leader Name]’);
$theemail = shittyarray($content, ‘[2_Leader Email]’);
$thedesc = shittyarray($content, ‘[4_Project Description]’);
$thecount = shittyarray($content, ‘[5_Count of people attending]’);
$thegroup = shittyarray($content, ‘[6_Total hours for the group]’);
$theprojdate = shittyarray($content, ‘[7_Project Date]’);
$theprojdate = trim($theprojdate); // to remove whitespace and crlf
if ($thegroup === ‘not found’ ) {
$thegroup = shittyarray($content, ‘[5_Total hours for the group.]’); }
$thehours = $extraf[‘9_Total hours for the group.’];
if ($thehours === ‘not found’ ) { $thehours = shittyarray($content, ‘[5_Total hours for the group]’); }
if ($thehours === ‘not found’ or $thehours == “” ) { $thehours = $thegroup; }
$attendees = shittyarray($content, ‘[8_Attendee list]’);
//$thedate = $extraf[’10_Project Date’];
if (strtotime($theprojdate) === false) {
//echo ‘We have a problem with ‘.$theprojdate.’ *******************’. ‘
‘;
$theprojdate = str_replace(“-“,”/”,$theprojdate);
//echo ‘after replacing dashes ‘.$theprojdate.’*********************
‘;
}
$aresult[$page->ID][“Name”] = $thename;
$aresult[$page->ID][“Email”] = $theemail;
$aresult[$page->ID][“Desc”] = $thedesc;
$aresult[$page->ID][“metakey”] = $page->meta_key;
$aresult[$page->ID][“Count”] = $thecount;
$aresult[$page->ID][“Hours”] = $thehours;
//$aresult[$page->ID][“Date”] = $thedate;
$aresult[$page->ID][“Date”] = $theprojdate;
$aresult[$page->ID][“Group”] = $thegroup;
$aresult[$page->ID][“attendees”] = $attendees;
$aresult_singled[$page->ID] = date(‘c’,strtotime($theprojdate));
// this DateTime would also convert a sloppy input date to a real date.
// sometimes a dash in the date instead of a / will cause this datetime to fail.
// so we convert the – to a / above and catch this here.
// this catch still errors, but it allows the page to continue.
// $ndate = new DateTime($theprojdate);
try {
$ndate = new DateTime($theprojdate);
}
catch(Exception $e ) {
//echo ‘Message: ‘ .$e->getMessage();
}
$totalaray[$ndate->format(‘M Y’)] += $thegroup;
$totalyaray[$ndate->format(‘Y’)] += $thegroup;
// $ndate = new DateTime($theprojdate);
// echo ‘hey’.$theprojdate. ‘ after ‘.$ndate->format(‘Y-m-d H:i:s’).’
;
}
}
arsort($aresult_singled);
//END of result loop
foreach ($totalyaray as $takey => $taval)
{ echo ‘
‘.$totalyaray[$takey].’ total hours in ‘. $takey . ‘ ‘. ‘
‘; }
?>
Create a Work Log Entry Here
Thank you!