Reset Article Hits with a Webhook in Joomla

Set the hit counter of all Joomla articles, a category or one article to zero by opening a secret address from a browser or cron job, using one PHP snippet.

Reset Article Hits with a Webhook in Joomla
Heads up! This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

You tested the site for a month before launch and every article now claims hundreds of views that never happened. Or you'd like to start the counters fresh every January. Joomla has no button for that, and editing the hits in the database by hand gets old fast. You can reset article hits with a webhook in Joomla with one PHP snippet in Code Snippets.

The PHP snippet code

The snippet listens for a secret parameter on any frontend address. When the secret matches, it sets the hit counter of your articles to 0 and answers with a short JSON message, so a script or a scheduled task can check the result.

use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
use Joomla\Database\ParameterType;

// The secret your webhook URL must carry, as in /?resethits=your-secret.
// Use a long random string and keep it private.
$secret = 'change-me';

// Do not edit below.

$app   = Factory::getApplication();
$input = $app->getInput();
$key   = $input->getString('resethits', '');

// Do nothing until you set your own secret, or when the key is wrong.
if ($key === '' || $secret === 'change-me' || !hash_equals($secret, $key))
{
    return;
}

$db    = Factory::getContainer()->get(DatabaseInterface::class);
$query = $db->createQuery()
    ->update($db->quoteName('#__content'))
    ->set($db->quoteName('hits') . ' = 0');

// Optional: reset one article (&article=ID) or one category (&category=ID).
$article  = $input->getInt('article', 0);
$category = $input->getInt('category', 0);

if ($article > 0)
{
    $query->where($db->quoteName('id') . ' = :id')->bind(':id', $article, ParameterType::INTEGER);
}
elseif ($category > 0)
{
    $query->where($db->quoteName('catid') . ' = :catid')->bind(':catid', $category, ParameterType::INTEGER);
}

$db->setQuery($query)->execute();

// Answer with JSON, so the caller can check the result.
$app->setHeader('Content-Type', 'application/json; charset=utf-8', true);
$app->sendHeaders();

echo json_encode(['reset' => $db->getAffectedRows()]);

$app->close();

Replace change-me in $secret with a long random string. The snippet does nothing while the sample value is still there, so no one can reset your counters before you've picked a secret of your own.

The webhook address is your site plus the secret:

  • https://example.com/?resethits=YOUR-SECRET resets every article.
  • https://example.com/?resethits=YOUR-SECRET&category=12 resets the articles in category 12.
  • https://example.com/?resethits=YOUR-SECRET&article=34 resets article 34 only.

The answer is {"reset":34}, where the number is how many articles had a counter above 0.

How to add this snippet

  1. Install Code Snippets if it isn't installed already.
  2. Log into your Joomla backend.
  3. Go to Components → Tassos Code Snippets.
  4. Click New.
  5. Enter a title, for example Reset hits webhook.
  6. Set Code Type to PHP.
  7. Set Insertion Method to Auto-Insert Locations.
  8. Set Location to On Page Load.
  9. Paste the code above into the editor.
  10. Replace change-me with your own secret.
  11. Click Save & Close.

Check that it works

  1. Note the hits of an article under Content → Articles.
  2. Open https://example.com/?resethits=YOUR-SECRET&article=ID in your browser, with your own site, secret and the article's ID.

The browser shows {"reset":1}, and the article's hits read 0 back in the list. With a wrong secret, the address shows your home page as usual and nothing changes.

To reset counters on a schedule, call the address from a cron job with curl, or from Joomla's own System → Scheduled Tasks with a task of the type GET Request.

The Clear the Cache with a Link in Joomla tutorial uses the same secret-link approach for the cache. To learn more about how PHP snippets work, read the PHP snippet docs.

Last updated on Oct 15th 2026 15:10