Using WordPress Custom Fields: Introduction

I decided a couple of weeks ago that I wanted to do an ongoing tutorial series with WordPress custom fields. At first, I thought I’d simply write a complete guide, but that idea seemed daunting. It seems far easier to break down the guide into individual posts in a series. Instead of writing a general guide, I will write detailed tutorials on specific and practical uses for custom fields.

I’ve been using custom fields for various tasks on this site for a while. A few places you can see some custom field uses on this site are:

  • On the Reading page, you can see all of my book reviews pulled into a nice organized list. Under each book’s title is the author’s name.
  • My Projects page, there is a list of several subpages. For each subpage, there is an image, title, and description. This list of subpages is made possible by custom fields.

These are fairly simple examples, and this tutorial series will cover more advanced uses later in the series. Mostly, I will cover what I think are practical uses of custom fields. Of course, suggestions are always welcome. So, if you want something specific, but can’t figure out how to do it, don’t hesitate to ask. This is a learning experience just as much for me as it is for you.

What are custom fields?

Custom fields are additional information that you can add to your posts and pages.

The good starting point is checking out WordPress’ Using Custom Fields. It’s a very basic tutorial, but will give you some idea of what custom fields are. The Undersigned has a good tutorial also. Neither of these tutorials cover a lot of uses, and I think that’s why many people don’t know what to do with custom fields — there are not enough detailed tutorials.

The truth is that you can do pretty much anything you want with custom fields. Your imagination is your limit.

Basic Usage:

The first thing you need to know is where to input custom fields. On “Write Page” or “Write Post” in the WordPress Dashboard, there is section at the bottom of the page that lets you input as many custom fields as you want. Here is a screenshot:

View of the WordPress custom field box in the admin panel

There are two different things you can input into a custom field — “Key” and “Value.” It doesn’t get much simpler than that.

What it is a Key and Value? The Key is the name of the custom field and the Value is simply the value you want to give to that name. For example, you might write book reviews and want to add some additional information like the book’s author or publisher, give it a link through your Amazon Affiliate membership, create a star rating system with images, or a multitude of other bits and pieces.

What do I do with this information? You can pull this information out in posts, on other pages, into sidebars, or wherever.

To give a list of your book reviews in alphabetical order with the author’s name, you could create a custom field with a Key named “author” and a Value of “The Author’s Name” for several posts, or reviews. After writing these reviews and putting them into your “Book Reviews” category, you would put together a page called “Book Reviews” or create a category-specific template for your “Book Reviews” category.

Here’s how you would list each book review (category=27 would need to be changed to your “Book Reviews” category ID):

<ul>
<?php
$book_reviews = get_posts('category=27&numberposts=-1&orderby=post_name&order=ASC');
foreach($book_reviews as $post) : setup_postdata($post);
?>
<li>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
<?php $author = get_post_meta($post->ID, "author", $single = true);
	if($author !== '') {
	echo 'by ' . $author;
	} ?>
</li>
<?php endforeach; ?>
</ul>

This is pretty basic, but I hope you’re getting some kind of an idea what custom fields are and what you might can do with them. I don’t want to give too much away on the Book Review use yet because I will definitely write a full-blown tutorial on how to add cool information to reviews.

Now, that you’re warmed up a bit, stay tuned by subscribing to the feed or bookmarking this page for future reference. I will link all the articles in the custom field tutorial series for WordPress here.

17 Responses to “Using WordPress Custom Fields: Introduction”

  1. Justin Tadlock

    [...] “Custom Fields” are a powerful part of Wordpress. Here’s a brief introduction. [...]

  2. Justin Tadlock

    [...] Tadlock wrote a whole series about using custom fields, which I’ve definitely got to take a closer look at when I have time, and one of these posts [...]

  3. Justin Tadlock

    [...] specifically, the Using Custom Fields page and the the_meta function. There’s also a nice run through of an implementation here and here. Popularity: unranked [...]

  4. Justin Tadlock

    [...] Wordpress Custom Fields 系列教程justintadlock.comCdrPlum æäº¤äºŽ æ•°ç§’ ä¹‹å‰ [...]

  5. Justin Tadlock

    [...] - Read: http://codex.wordpress.org/Using_Custom_Fields - WordPress custom field guide. - Read: …using-wordpress-custom-fields-introduction - my personal tutorial on custom [...]

  6. Justin Tadlock

    [...] before. - Read: Using Custom Fields « WordPress Codex - WordPress custom field guide. - Read: Using WordPress Custom Fields: Introduction: Using WordPress Custom Fields tutorial series - my personal tutorial on custom [...]

  7. Justin Tadlock

    [...] Using WordPress Custom Fields tutorial series - [...]

  8. Justin Tadlock

    [...] knowledgeable on the subject. One more thing I may suggest ATM is looking at this basic tutorial: Using WordPress Custom Fields: Introduction: Using WordPress Custom Fields tutorial series This quote from the article *might* be able to apply to what you want: [...]

  9. Justin Tadlock

    [...] understanding of WordPress, themes, and php in general. In fact, in going through his custom field tutorial, I was even inspired to make a couple of custom sidebar widgets for this theme using his [...]

  10. Justin Tadlock

    [...] to learn more about this powerful and underutilized function of WordPress. Justin has a great tutorial on getting started with custom fields. Thomas Silkjær also has a brief tutorial on his site that [...]

  11. Justin Tadlock

    [...] It has a bit of a web-magazine look about it - with a slick YouTube video in the sidebar,  and post highlights using custom fields.  [...]

  12. Justin Tadlock

    [...] 1)Using WordPress Custom Fields: Introduction- An ongoing tutorial series for practical uses of WordPress custom fields [...]

  13. great thanks a lot

  14. great
    thank you..

  15. No problem. ;)

  16. Justin Tadlock

    [...] 1)Using WordPress Custom Fields: Introduction- An ongoing tutorial series for practical uses of WordPress custom fields [...]

  17. Justin Tadlock

    [...] 1)Using WordPress Custom Fields: Introduction- An ongoing tutorial series for practical uses of WordPress custom fields [...]

Leave a reply

Log in or Register



XHTML: You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> 
<blockquote cite=""> <cite> <code> <del datetime=""> <em> 
<q cite=""> <strong>