If you manage a large Joomla site, you probably are wondering why Joomla comes with no admin content search; only a Title search filter for the Article Manager. I’m not sure why Joomla 1.5 and earlier versions didn’t have this feature because it only takes a few lines of code, but having a search filter on the content and not just the article title is valuable to have for administrators.

Screenshot of content filter in the Joomla admin

Why would you want this?

Say you have an image or document that should be referenced in an article, but you can’t remember which one (if you referenced it at all).  Well with the content filter you can easily look for that reference in your content.  Here is how setup Joomla to do this simple function for you.

What files to edit?

In Joomla 1.5.8 you need to modify two scripts.  These are:

  1. /administrator/components/com_content/controller.php
  2. /administrator/components/com_content/admin.content.html.php

Let’s start with admin.content.html.php

Under the showContent function, I suggest changing the ‘Filter’ label to for the title search box to ‘Filter by Title’ or something like that.  So line 52 should read:

<?php echo JText::_( 'Filter by Title' ); ?>:

After the search input html tag on line 53, add the following code just below.  This is the html for the content filter:
<?php echo JText::_( 'Filter by Content' ); // wpg - adding a content filter?>:
<input type="text" name="search_content" id="search_content" value="<?php echo $lists['search_content'];?>" onchange="document.adminForm.submit();" title="<?php echo JText::_( 'Filter by content' );?>"/>

then on the Reset button code at line 60(ish), add the following to the onclick event to reset the content search box when the reset button is pressed:
That is all the code we need to add to this script. Now we just need a few more lines of code in our controller and we are all set.

Finishing up with controller.php

Now that we have added the html for our content filter we need to add the code that will actually perform the search.  Here we go.

Within the viewContent function, go to about line 65 (just below where the $search variable is set and add the following.  This will grab the string or phrase we are searching on.
$search_content = $mainframe->getUserStateFromRequest('articleelement.search_content',        'search_content',    '',    'string');
$search_content        = JString::strtolower($search_content);

Now we need to modify the query to the database.  So at about line 125 (below where the keyword filter is set) add the following lines.  This will check to see if the word or phrase is in the introtext or fulltext of the articles.
if ($search_content) {
$where[] = 'LOWER( c.introtext ) LIKE '.$db->Quote( '%'.$db->getEscaped(
$search_content, true ).'%', false ).
' OR LOWER( c.fulltext ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_content, true ).'%', false );

The content search should now work but we want to add one more line of code so that when we do a filter, our filter request is saved in the text box.  So at the end of the function, just before the ContentView::showContent function call, we need the following line of code (at about line 205):
$lists['search_content'] = $search_content;