Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
231 views
in Q2A Core by
How can I delete all posts containing "Tag" ?
by
Do you mean posts containing the given word, or posts tagged with that word?
by
posts tagged with that word

1 Answer

0 votes
by
selected by
 
Best answer

Fetch the IDs of questions tagged with a given word with a query like this (replace the ellipsis '...' with your actual tag word):

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='...';

Use the PHP code from my answer to your other question for deleting the posts.

by
It just worked
by
How to do it for posts containing the given word
by
<?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);
?>
by
Replace qa_posttags with qa_contentwords. Note, however, that this could return answers and/or comments as well, not just questions.
by
And again, deleting Q2A posts via SQL queries is NOT recommended b/c Q2A does a lot of internal caching. Use the proper Q2A methods to avoid problems.
...