• Resolved demonboy

    (@demonboy)


    Morning all,

    I’m just teaching myself custom fields and I want to call up each field for the post separately. I don’t understand how to do this – could someone give me an example? I think I use ‘get_post_meta’ but how do I call my ‘lon’ key for the post? I’m using the following but it is not showing anything:

    <?php get_post_meta($post->ID, 'lon', true); ?>

    I need a working example to help me learn and I don’t see one in the documentation.

    Thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • There’s 2 basic methods, and one doesn’t do what you want. That one first, is, of course,
    http://codex.wordpress.org/Template_Tags/the_meta

    The nice thing is it shows allllll your custom fields, like this:

    Key: Value
    Key: Value
    My Mood: Happy
    My Thumbnail: happythumbnail.jpg

    Another handy tip is, there is another thread on this forum (lemme know if you can’t find it) where someone gave me the code to Exclude certain keys from that list. So you can show all your custom fields EXCEPT certain ones that you want to hide.

    The problem is you said you want to display them separately, where the above method is not separate.

    To do that, method 2. You need to type the Keys on your own, hardcode them, then use PHP or a plugin to call in the Value. So on the left you can actually write whatever you want as your label in place of the actual name of the Key. Then on the right put your PHP code to pull in the Value. Example,
    Today I feel very 'get custom field value for the key My Mood'

    The ways of getting the custom field value are either:
    With a plugin,
    http://wordpress.org/extend/plugins/get-custom-field-values/

    Without a plugin,
    http://codex.wordpress.org/Function_Reference/get_post_meta

    More info in general here,
    http://wordpress.org/extend/plugins/get-custom-field-values/

    hope this helps you explore the many ways as you’re teaching yourself about this

    Thread Starter demonboy

    (@demonboy)

    Thank you very much for your reply, Dgold. I have since licked the get custom field with both your help and further searches. It really is the answer I’ve been looking for and am very excited about it!

    Thank you once again.

    Glad you made it work!

    I realized I put the wrong link for “General” info, I meant to show this link too,
    http://codex.wordpress.org/Using_Custom_Fields

    for anyone else’s benefit who may see this later

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Fields – calling up separate field’ is closed to new replies.