This is a somewhat uncommon request, but I have a client that wants to provide a custom HTML formatted email once a month to users. The users should only receive product notices based on their choices in their sign up form that they initially signed up with.
I am using a Cron Job to process the PHP code. It will loop through all the users and return the relevant lead ID from the database (already working). My question now is - I know the form ID, I know the lead ID - but how do I get the form OBJECT so I can start to manipulate it and pull data from it?
Below is the code I have in the for each user loop - please help!
global $wpdb;
//Figuring out if user has submitted form before
$sql = "SELECT filtered.sort, l.*, d.field_number, d.value
FROM wp_rg_lead l
INNER JOIN wp_rg_lead_detail d ON d.lead_id = l.id
INNER JOIN
(
SELECT @rownum:=@rownum + 1 as sort, id
FROM
(
SELECT distinct l.id
FROM wp_rg_lead l
INNER JOIN wp_rg_lead_detail d ON d.lead_id = l.id
WHERE
l.form_id=". $_GET["formid"] ."
AND created_by=". $iUserID ."
AND status='active'
ORDER BY date_created DESC
LIMIT 1
) page
) filtered ON filtered.id = l.id
ORDER BY filtered.sort";
//initializing rownum
$wpdb->query("select @rownum:=0");
//getting results
$results = $wpdb->get_results($sql);
$resultArray = array();
foreach( $results as $result ){
$leadID = $result->id;
}
echo $leadID;
The code above does return the correct leadID, but for some reason in the for each results it does loop multiple times when it should only loop once for one result. I am not concerned with that near as much as getting the form object so I can get the relevant checkbox data though.
Thanks for any help.