I have a Wordpress site and a front end posting form on it.
When form is submitted, the user gets link to his email with unique string (example 432879374982) saved as a custom field and post gets status "pending":
http://www.mysite.com/verify.php?verify=432879374982
I now want to change status to "published" when user click on a link.
I know that I should use GET parameter, and check if the string is saved in database, and publish the post where there is a match in db, but dont know how to code this.
EDIT:
Made it working!
In the landing page- on wordpress I created a page named "verify" and in template (php) I included code from @Bora- only the database connection has to be established before and it changes the status of a post.
Status has to be set as "publish", not "published"
Try something like following codes:
$verify = $mysqli->real_escape_string($_GET['verify']); // escape GET var
$query = "SELECT * FROM table WHERE code = '$verify'"; // Build query
if ($result = $mysqli->query($query)) { // Check return query
while ($row = $result->fetch_assoc()) { // Fetch Row
$query = "UPDATE table SET status = 'published' WHERE code = '$verify'"; // Update query
$mysqli->query($query); // Run query
}
$result->close(); // free result set
}