Testing Meta custom fields


(Update added 06-08-2004 10:50am)

I am testing a WP feature, the meta custom fields. This post will show what I’m reading, eventually, if I can make it work. Does it show up?

Yes it is working. Here’s what I did, as I wrote on the WP Support Forum:

OK Here’s How I Did It just now:

I made a post and created a "Reading" key in the custom fields area below the writing area of a post. In the "value" I put a book I’m reading.

I then saved the post, and then chose the drop down "select" to choose "Reading" from the "add a new custom field" and input a second book I’m reading into that value field.

So I had two custom keys there, both called "reading" with different values, a different book each.

On the index.php template I put this:

<br /> <?php the_meta() ; ?>

in the same div as holds the post title and categories the post is filed under, etc. I have it placed underneath all that stuff so that it shows up last.

I published the post and this is the output I got:

"Reading: Pendragon Cycle, Mansfield Park"

This is what it looks like on the Source of the web page:

<br /> <ul class='post-meta'>

<li><span class='post-meta-key'>Reading:</span> Pendragon Cycle, Mansfield Park</li>

Posts that have no custom field entries do not show any of the above last code on the source … so only meta data shows up this way in posts that it’s entered as this thread is stating.

I puzzled over this thread and custom fields a few times the last week, and then decided to tackle it today. It took me 5-minutes to finally read, and implement, so I wanted to write this so that anyone else can figure out how to at least put per-post-meta-data in via custom fields.

It was simple. I look forward to seeing further implementation from plugins and new tags!

UPDATE: This thread on WP’s forums expands on the above. Idahocline on the forum wrote a function for “the_meta” so just using that in my-hacks.php [I use WP 1.2 and have legacy support for my-hacks turned on in options.] gives me the ability to split up the keys on separate lines, and put them anywhere in the post loop that I want, or not show some, though they are still attached to the post. Basically it allow formatting of the keys and values. This functionality is nice, since I’d added a second key to this post, and didn’t want the two keys with their values all on one line smooshed together, as they were. I couldn’t easily figure out how to work with the_meta to do what I wanted, since it’s a new thing — it needs developed further. Isee great value in custom fields, and using them for me can highlight books, music, or whatever, as well as if a post is specially needing to be marked, as I have marked this one with WP HELP since it’s a post totally about “the_meta” tag in WP. This way I’ll be able to, in the future, call up this post in different ways do to custom fields, the_meta. ๐Ÿ™‚


3 responses to “Testing Meta custom fields”

  1. very basic (i hope!) editing question here – which files did you modify so your the_meta section has the
    and bullet points removed, AND has your book titles in color?

  2. Very basic, but not entirely simple!

    I ended up using a function that you can copy on the forum [link in post post above, near the bottom, “Update: This Thread” being the link]

    Put that in your MyHacks file. You must be using 1.2 or above for the meta_cache field to work, so you also need to be sure you have Legacy My Hacks support chosen in Options.

    In the My Hacks file I Duplicated the function, giving it a new name, and did that for each kind I thing I wanted to style differently.

    In the function you can easily see what the structure is for how you can style your meta keys.

    So in the functions you have to change the name of different classes so that they’ll be unique values.

    Take those new classes and add them into your wp-layout.css file, and that’s where you’ll do the magical changes.

    In your index template you’ll need to place the key’s where you want them, which is a php code. The basic meta key with the function I linked to is

    the_meta_key("WP Help")

    That code will use the basice function with ANY meta key that is called for in the variables. This I use for basic information. I didn’t want my reading and music to be looking the same, so I duplicated the functions, as I said above, and each now has their own styling. (I’m not done styling mine either, I let the project sit, never intending Christmas colors to stay! ๐Ÿ™‚ )

    So here’s what I have on my index template for the reading key, wrapped in php code:

    the_reading_key("Reading")

    How does that code show up when the page is called in a browser? I can’t get that to show up on the post. Sorry. It’s on the source of the page though, if you want to find it there.

    You’d see in the source as stated above that I have css classes specifically for my reading key and that function.

    That’s how I style the meta keys differently.

    Using this function you can put the keys anywhere in the post which they are attached to. So once you do this, you’ll need to consider that when you add new custom fields to a post they won’t show up on the post in index.php unless you create a code on the template for the new key.

    I’ve decided to use the custom keys in this way, to have specific uses show up, and add any keys I want to that are different, and that sometime in the future I’ll have a use for displaying them.

    The thing about the function is that it’s just a way to display custom meta keys. The meta keys can ALL be displayed in that vanilla way using ). It doesn’t do what I want though. Functions must be created to make it a useful field to use.

    I hope I’ve answered your questions. If you need some additional help, feel free to ask!

  3. awesome — this works!! i’m going to keep it simple and keep my colors all uniform (ie no Christmas colors..haha)…that’s enough for my cutting & pasting skills for this week. ๐Ÿ™‚

Leave a Reply

Your email address will not be published. Required fields are marked *