WordPress.org

Support

Support » How-To and Troubleshooting » Multiple Custom Fields

Multiple Custom Fields

  • Hi,
    I understand how to use the custom fields and all, but what I don’t understand is how manage multiple custom post fields in a customized way. I understand that if I put the “the_meta” PHP tag in there, I will get a list view of ALL of the custom fields showing up (which looks dumb).
    What I want is to be able to have full control of each custom field seperately. I’d like to have custom fields in different locations (say 1 below the post, and one in a table off to the left, etc), and I’d like to be able to customize the full output to it and all…
    Is this possible with WP?

Viewing 14 replies - 1 through 14 (of 14 total)
  • you have to code a function which will extract one meta at a time….should not be so difficult.
    If you want as soon as I finished what I am working on, I can have a look….

    And what would be nice it to be able to use only the value OR the key as an output in the page. This way you could choose a key called “newssubtitle” and in the page the saved value of this key, which could be a few lines long if necessary. Or perhaps via includes? If the key would be an include statement such as <?php include(‘newssubtitle.php’); ?> and only the key would be visble in the page, you could easily insert complete phrases, textpages, images, etc., with just selecting that code.
    The only problem is, I tried that before, is that at this point when you insert code, like <img src=”images/images.gif”>, this is not remembered when you start a new post or edit the old one as a value by WP. I thinks it’s a bug of some kind.

    Thanks for the answers guys 🙂
    Yes idahocline, if you are “cooking” something up for this, PLEASE let me know when it’s done! Thanks! 🙂
    I personally think the way it’s set up now is very disappointing, because it’s lack of flexibility makes it a useless feature. 😉

    This should provide few hints…. :
    The function below extracts a specfic meta-tag from the existing ones. If none found, nothing is out. If the specified “tag” is empty than it works as “the_meta()” function.
    It is not tested but should work with 1.2. I only updated the code of “the_meta()” function so….

    function the_meta_key( $tag='') {
    global $id, $post_meta_cache;
    $inUL = false;
    if ($keys = get_post_custom_keys()) {
    foreach ($keys as $key) {
    if ($key == $tag || $tag=='') {
    $values = array_map('trim',$post_meta_cache[$id][$key]);
    $value = implode($values,', ');
    if (!$inUL) { echo "<ul class='post-meta'>\n"; $inUL = true; }
    echo "

  • <span class='post-meta-key'>$key:</span> $value
  • \n";
    }
    }
    if ($inUL) { echo "
    \n"; }
    }
    }

Thanks Idahocline!
Just a few questions… where is this code supposed to be added?
And how is this code supposed to be used? I’m not all that great with PHP…. maybe you could fill me in please 🙂
I just don’t understand how that code can let me have custom fields show up in different spots, appear different, etc.
Thanks! 🙂

put the code in my-hacks.php .
In “index.php” in the “main loop”, during the “post” processing, just put ‘<?php the_meta_key(“mood”); ?>’ where you want to have your “spot”…Of course, replace “mood” with the key you want ! ;o)

Sweet!!! thank you so much!
I’ve had troubles running that damn myhacks script… would it still work if I just put that code in the index page?

yes…BUT don’t forget if you upgrade your wordpress : remove the index.php from your upload to your server otherwise all updates you’v done will be lost ! (it is not the case with “my-hacks.php”)….

Thanks again SO MUCH!!
(BTW, I was the anonymous person above) 😉

;o)

Thanks idahocline, that function code makes the_meta () much more useful! I figured out how to basically use the_meta () last night, so this is the next step in good functionality for it. Thanks! 🙂

I posted here with more about how I used the_meta_key . Useful to get going on how to use this hack as well.

idahocline, I’m not so good at tearing apart php code and putting it back together, as in understanding it when I look at it, but not sure how to use examples there are out there to re-build it to do something a bit different, like:
Could you make that code up their to “explode ()” the values so that if a key has two or more values in one post, it’ll return the data as such:
$Key:
$Value 1
$Value 2
$Value 3
….etc.
If it was clearly done then so that utter customization could be done via .css … it’d be grand.
I’ve used the idea up above that you posted wonderfully to work. But now I just am getting other custom functions out of it to control the output design via .css
So I’m stuck on not knowing how to explode the $values
I appreciate any effort you can give that will educate me further in the beauty of php code. Knowledge I am thirsty for 🙂

a really good plugin that makes much of this easier is the Get Custom Field Values at http://www.coffee2code.com/archives/2004/06/30/plugin-get-custom/

I just installed it yesterday, and the coder is very helpful, and I got it working and doing some very cool things!

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Multiple Custom Fields’ is closed to new replies.
Skip to toolbar