• Resolved Joe Hall

    (@redbmedia)


    Is it possible to display feilds one at a time? I use costom fields in several of my blogs and I now want to be able to display them one at a time versus the standard unordered list. I currently use <?php the_meta(); ?> in all of my template files. Do I need to use something like <?php the_meta(key); ?> ??

Viewing 13 replies - 1 through 13 (of 13 total)
  • You’ll need to use get_post_meta which requires some more reading.

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    He won’t necessarily need get_post_meta() in particular, but get_post_custom(), get_post_custom_keys(), get_post_custom_values(), will also come in handy. That codex link is the right page to point to. πŸ™‚

    RedBMedia: How you code it up depends on what specifically you’re trying to do. Custom fields can be displayed, but they rarely are. the_meta() is mostly only useful for debugging and such.

    Thread Starter Joe Hall

    (@redbmedia)

    Thank you both. According to the post that you just refered me to it appears that get_post_custom_values($key) is what i am going to have to use. However, below that section it says that the_meta() is the only template function regarding custom fields, is this true? and if so does that mean that I can’t use get_post_custom_values($key) in my templates?

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    No, you can use get_post_custom_values($key) in the Loop and templates without issues.

    Thread Starter Joe Hall

    (@redbmedia)

    Thank you Otto. However, when I use <?php get_post_custom_values($key) ?> in my templates nothing appears…any ideas?

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    No, it’s not supposed to make anything appear. What, exactly, are you wanting to do here? What exactly do you mean by “display them one at a time”?

    get_post_custom_values() will let you get the value(s) for a specific key, but it doesn’t display it.

    Without specifics on what you want to do, I can’t really tell you how to do it.

    Thread Starter Joe Hall

    (@redbmedia)

    I am pulling alot of data off of another server and displaying it on wordpress. Most of what is being pulled off, are pictures. Every picture that I am working with has a unique URL that follows a standard format such as: www.theotherserver.com/images/198747.jpg I have gotten permission to “hotlink” these pictures from the other server. Up until this point I have been just writing new IMG tags eachtime I want to hotlink. But I am tired of doing that so I want to write some code like:

    <img src="www.theotherserver.com/images/<?php get_post_custom_values($key) ?>.jpg">

    So that all I have to do is type in 198747 in a custom field area. That is why I asked about displaying one key at a time because I have many custom fields for each post but I only want one inserted into the IMG tag. Is any of this possible?

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Ahh.. Okay.

    You want something like this:
    <img src="http://www.theotherserver.com/images/<?php echo get_post_custom_values("image-key") ?>.jpg">

    Then you’ll have the custom field with a key of “image-key” and a value of “198747” and such.

    The “echo” is what you’re looking for here.

    This IMG code won’t be in the post though, it’ll have to be in the Template (and in the Loop), of course.

    Thread Starter Joe Hall

    (@redbmedia)

    Thank you, after I typed out my last explanation I thought “hmmm….echo?” and sure enough I was right! Thanks again! Thank god for the support forums!

    Thread Starter Joe Hall

    (@redbmedia)

    Ok,I know that I already marked this as resolved but I actually went and tried everything and things didn’t work, all I got was an image tag wit “Array” where the custom feild key is supossed to go. In other words when I use this code:

    <img src="http://www.theotherserver.com/images/<?php echo get_post_custom_values("image-key") ?>.jpg">

    I end up with:

    <img src="http://www.theotherserver.com/images/Array.jpg">

    Any Ideas?

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Ahh.. Okay, try this instead:

    <img src="http://www.theotherserver.com/images/<?php $values = get_post_custom_values("image-key"); echo $values[0]; ?>.jpg">

    Thread Starter Joe Hall

    (@redbmedia)

    Ok, I actually tried it this time before closing out! And it works great! Thanks alot for your help!!

    I’m trying to get the same effect except i only need to display one image per page… right now, i’m using this…<div id=”sidebar”><img src=”http://www.breschcraft.com/gorges/wp-content/themes/fallseason-10/images
    <?php $values = get_post_custom_values(“sidebar_page_img”); echo $values[0]; ?>.jpg”>
    </div> this is cool, because I can actually see where an image would be displayed, but unfortunately there is no image. I just need to dislay a unique image per page…. I’ve probably overcomplicated all of this. Please help!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Displaying Custom Fields One At a Time.’ is closed to new replies.