Thanks for reply, I had implemented the script and tried to run file placing in wordpress under 'public_html/sampleDeleteEntries.php' folder. I think its not connecting to Formidable Entries. Can you please verify, if I am missing or doing anything wrong.
Below is my script file 'sampleDeleteEntries.php'
$form_id,
'start_date' => $start_date,
));
// Check if entries were found
if ($entries) {
// Loop through entries and delete them
foreach ($entries as $entry) {
//FrmEntry::destroy($entry->id, true); // true parameter for permanent deletion
$deleted_count++;
// Print the deleted entry ID
echo "Deleted Entry ID: {$entry->id}\n";
}
// Print success message with total count
echo "Successfully deleted {$deleted_count} entries for Form ID {$form_id}.\n";
} else {
// Print message if no entries found
echo "No entries found for deletion.\n";
}
}
// Set the Form ID
$form_id = 5; // Replace with Form ID
// Calculate start date for entries older than 24 hours
$start_date = date('Y-m-d H:i:s', strtotime('-24 hours')); // Go back 24 hours
// Delete entries and print messages
delete_entries($form_id, $start_date);
?>
A few things. 1. The beginning of your code paste is incomplete, so it's not clear what the full code is. 2. What do you mean by " I think its not connecting to Formidable Entries.", i.e., what messages are you receiving on the front end or in a log file? 3. What is the code for "delete_entries"? 4. I suggest using some sort of online code pasting website for sharing code here because the formatting is pretty much non-existent. 5. You may be missing the following code to load up WordPress in your standalone program:
$path = preg_replace('/wp-content.*$/','',__DIR__);
require($path . '/wp-load.php');
Thanks for reply. After adding Library Path. Script able to execute with below fetch 2 records.
$entries = FrmEntry::getAll(array('it.form_id' => $form_id), ' ORDER BY it.created_at DESC',2);
But in my case, I need to fetch/query entries till specific date range, for that I had constructed below query, But its not working even though old records are present in Entries. Anything I am missing in constructing query please guide me.
$entries = FrmEntry::getAll(array('form_id' => $form_id,'where' => array('created_at $start_date, ), ));
Where $start_date format is 'Y-m-d H:i:s' and value getting passed is '2023-12-24 10:27:12'.
That command isn't syntactically correct because you don't have an operator to associate the column name and the value. I'm surprised you didn't get an error. It's potentially better to do something like this, using a direct SQL command as seen here - https://pastebin.com/35yTek9E . NOTE: I didn't test this.
$entries = FrmEntry::getAll(array('form_id' => $form_id, 'where' => array( 'created_at <= %s' => $start_date), ));
Please login or Register to submit your answer