I'm developing a small plugin for Joomla 3.x that adds a "Trash article" button when you're in Joomlas Frontend. See screenshot below.


Now I have this AJAX call that happens when you click on the list item.

Here's the code:

request = {
          "option" : "com_ajax",
          "plugin" : "deletearticle"
          "data"   : "test",
          "format" : "raw"  

       type : "POST",
       data : request,
       success: function (response) {
           $("p:first").html("Data: " + response)

And the helper PHP file.

 class plgAjaxDeletearticle extends JPlugin
    function onAjaxDeletearticle()
        $controller = JControllerLegacy::getInstance('Content');

I'm right now doing work experience and I asked my mentor how I should change the article state to trashed. And he gave me the code inside the function and told me that I should be able to modify it in some way, so that the controller will execute a save function on the article.

I've tried and read up on this stuff but it doesn't seem to be all that well documented. Any help would be greatly appreciated as I'm not quite sure how I should proceed.


1 Answer 1


First of all you need to pass article ID with your request. Then you can use JTable class to update the state:

public function onAjaxDeletearticle()
    // Get id from the request
    $id = JFactory::getApplication()->input->getInt('data');

    // Get the new instance of #__content table
    $table = JTable::getInstance('content');

    // Load the article data by id

    // Set the state to 'trashed'
    $table->state = -2;

    // Store the article

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.