Skip to content
Mar 16 / Morris

Custom Fields for Categories – WordPress

There are endless reasons why it could be helpful to use customs fields on categories pages in WordPress – and it seems many other WP users agree. The users here speak about some plugins that are now out of date – so thankfully, there’s now a painless, fool-proof way to get this working.

1. Download HeadSpace2

Firstly, you need to download and install the HeadSpace2 SEO plugin. As well as being a mean SEO plugin (far beyond All-In-One or any other plugin you’re probably used to), HeadSpace2 lets you create custom meta data on pages, posts or categories – exactly what we need!

2. Update Page Modules

Once the plugin is activated, navigate to Settings > HeadSpace > Page Modules and drag the Custom Meta into the green Simple box – see below.

category-custom-fields

3. Add the Custom Values

Select the edit box on the right and add the custom fields you’d like to display on your category pages. I’m building an affiliate portal so have added “free-bingo-value”.

category-custom-fields-wp

4. Edit Categories

The custom fields will now show up on your category description pages – towards the bottom. Add the value you require and update. Here you can also add any of the other modules you selected above – Page Description and Keywords, for example.

5. Call the Custom Fields

Call the custom fields anywhere (see update below) in your theme by using the following PHP code, replacing the custom field name (‘free-bingo-value’) with your own.

<?php echo MetaData::get_custom ('free-bingo-value'); ?>

Simple as that! It’ll show up without any styling, but you can place tags around it to display as you require. See the custom values on the bingo site – Red Bus Bingo.

Update:

I’ve crossed out anywhere because I’ve heard from some folks who couldn’t get it to show up on single pages.

Of course, I realise now why anywhere was far too optimistic! If you’re going to call the custom value on a single page (or anywhere in the post loop), it’s going to look for the ‘free-bingo-value’ custom value for that particular post – not for the category. So stick to pasting this on your archive.php or category.php templates.

6 Comments

leave a comment
  1. Trish / Apr 16 2010

    I want to query my custom field. For example I have a custom field called genre and the value is romance. I want to query the value romance to list all the categories that contain the word romance. How can I do this?

  2. Morris / Apr 21 2010

    Hi Trish.

    I’m afraid that WP, and the Headspace plugin, aren’t robust enough for this at the moment.

    I would recommend using “genre” as a category and “romance” as your sub-category. You’ll then have far more control over how you can call and display those fields.

  3. Fahd Murtaza / Apr 27 2010

    Is there any fix for showing the custom field value within post loop as its where I want to use it. Any help is highly appreciated. Thanks.

  4. Morris / Apr 27 2010

    With this method, no. Hopefully WP will take in all the feedback regarding custom fields and there will be increased options in future releases.

  5. דנטלי / May 19 2010

    Finally a solution for this! Never knew that plugin existed

  6. Morris / May 26 2010

    Does anyone know whether custom fields for categories has been incorporated into WP3.0?

Leave a Comment