<?php
// Replace these variables with your Q2A database credentials
$databaseHost = '';
$databaseUser = '';
$databasePassword = '';
$databaseName = '';
// Replace 'fluther' with the tag you want to delete
$tagToDelete = 'music';
// Establish a connection to the Q2A database
$connection = mysqli_connect($databaseHost, $databaseUser, $databasePassword, $databaseName);
if (!$connection) {
die("Connection failed: " . mysqli_connect_error());
}
// Find post IDs with the specified tag
$query = "
SELECT q.postid
FROM qa_posts q
INNER JOIN qa_posttags t ON q.postid = t.postid
INNER JOIN qa_words w ON t.wordid = w.wordid
WHERE w.word = '$tagToDelete';
";
$result = mysqli_query($connection, $query);
// Delete posts containing the specified tag
while ($row = mysqli_fetch_assoc($result)) {
$postID = $row['postid'];
// Delete associated answers (child posts) first
mysqli_query($connection, "DELETE FROM qa_posts WHERE parentid = $postID;");
// Delete the main post (question)
mysqli_query($connection, "DELETE FROM qa_posts WHERE postid = $postID;");
}
// Close the database connection
mysqli_close($connection);
?>