Facetious: CFTP’s Advanced Search plugin for WordPress

Out of the box: a Facetious widget in Twenty Ten

We’re proud to announce that Facetious, a plugin we’ve been working on for quite some time, has now been released in the official WordPress repository. And we’d like to thank the UK taxpayer for his/her assistance in writing it.

We do a lot of work for government departments, and on several recent projects, there’s been a requirement for an ‘advanced’ or ‘faceted’ search form. This allows you to search by post type, by keyword, by taxonomy, and by month – all together. You can see it on the Government Olympic Communication site, for example, where we let you search its video library (post type) by keyword, and/or theme, department, nation/region, video quality, or month of upload.

We did something similar for the Commission on Devolution in Wales; and it’s a key feature of another site due to go live in the next month or so.

We’re in good company, by the way: you’ll see a very similar search form on GovUK’s Inside Government pages, for example.

It became immediately obvious that we could write the code as a plugin, for instant reuse on any WordPress site. We called it Facetious, because it had the word ‘facet’ in it. And in keeping with our open source principles – not to mention the fact that the development work had been funded by government departments – we decided we would release it publicly in the official WordPress plugin repository.

Out of the box, it provides an enhanced ‘search form’ widget, which you can drop into any WordPress sidebar. If you want to add a customised form into your own post templates, we’ve made that easy too: it’s all detailed in the plugin’s readme file.

Facetious isn’t a ‘search engine’ per se: it’s just a simple way to construct complex multi-dimensional queries. The results are gathered using WordPress’s built-in search function, which doesn’t try to be anything too clever. If you’re looking for smarter search results, you’ll need a different plugin. (Maybe Relevanssi or something.)

Oh, there’s one more thing.

Search URLs in WordPress are the platform’s last unpretty ‘permalink’. Nobody wants to see ?s=keyword in their address bar; and it isn’t possible to cache query-string URLs using something like WP Super Cache. So we’ve created a new permalink structure for searches as part of Facetious, and your search URL now looks like /search/keyword/ – or /search/month/201302/keyword/whatever/category/uncategorized/. This will be applied to any search: not just those submitted via a Facetious form.

If you want to give it a try on your own WordPress site, just go to Plugins in the admin area, and search for it. If you’re a developer, and you’d like to help us improve Facetious, it’s also on Github. Pull requests welcome. ;)

My thanks to Nick H, Nick S and Sara P for letting us experiment on their sites over the past few months: and to John Blackbourn, for doing such a fantastic job turning my hacky code into a plugin to be proud of.

On government organograms and RDF files (includes free WordPress plugin!)

There was an initial buzz of excitement yesterday, at the launch of the new data.gov.uk interactive organograms… and then, by teatime, a bit of a backlash. I can see both sides myself. Yes, it’s a very cool rendering of potentially quite dull data, and it’s nice to see it done in javascript (jQuery) rather than Flash… but it’s actually a bit fiddly to navigate through. That isn’t to understate the significance of the achievement, though: such a coordinated leap forward, in both technical and bureaucratic terms, is no small task. And there’s so much to it, most of which is beyond me, that I can’t begin to explain it in depth. Hopefully someone else will oblige.

As part of the initiative, departments have been instructed to upload raw RDF files to their websites, from which the organograms can be generated… which caused a bit of a problem for one of our clients. But it’s a problem we’re happily able to solve.

The Wales Office was the first Ministerial department to move everything over to WordPress, back in early 2008; and they’ve been running very happily on it ever since. About a year ago, we helped them build a new Transparency section, which acts as a download area for (mostly) Word and CSV files. It’s all rendered via a custom page template, and managed via the standard WordPress ‘media library’ functionality. Unspectacular perhaps, but quick and easy for all concerned.

However – when they tried to upload an RDF file, they couldn’t. WordPress has a surprisingly long list of file types it’s prepared to let you upload (look for get_allowed_mime_types() in wp-includes/functions.php): but RDF isn’t on it. So it throws up an error message like this:

We could upload it as a zip file, which would have the added benefit of reducing the file size by 90-odd per cent… but then the orgchart generator wouldn’t be able to process it. Dilemma.

But as ever with WordPress, there’s a happy ending to the story. We – by which I specifically mean my technical partner, Mr Wheatley – were able to write a quick plugin to ‘hook’ on to approved filetype list, and stick RDF on the end. Problem solved, file uploaded, everyone happy. You can see the successfully uploaded file here.

And given that there are a good number of government departments running WordPress sites, including at least one other using WordPress specifically for its transparency information, we thought we’d do the decent thing, and offer it up for others to download. Here you go. There’s no configuration interface needed; just upload it, activate it, and start chucking up RDF files to your heart’s content.

WordPress plugin: Robots.txt Reminder

Robots.txt Reminder

I’m sure we’ve all done it. You’re creating a new WordPress installation, and for a bit of privacy whilst you build the thing, you choose not to ‘allow my blog to appear in search engines like Google and Technorati’. But in the rush to get the site out the door, you forget to switch the setting to make it ‘visible to everyone, including search engines’.

So I’ve created a laughably simple WordPress plugin called ‘Robots.txt Reminder’, which adds a notification message to the top of all Admin pages if it detects that (a) your blog is set to block search engines, and (b) your user capabilities allow you to make the change. It’s kinda hard to ignore, but that’s kinda the point.

Click here to download robotreminder.zip, then – assuming you’re using one of the more recent versions of WordPress, and are able to do automated updating – upload the zip file as-is, by clicking on Plugins -> Add New -> Upload.

It’s not the first plugin I’ve ever coded, but it’s the first plugin I’ve ever ‘released’ like this, so please be gentle. :)