WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to enable custom field in metadata for 2.51 (4 posts)

  1. Drawer
    Member
    Posted 5 years ago #

    Hello, it has taken me hours. And hours. And I still don't know why none of the Custom Fields I fill out show up on my new blog.

    But anyway, I want one of them there, that I call Weather. I now have a place for it, underneath the Tags. However, I can't figure out how to add the value. I have studied this one Codex page http://codex.wordpress.org/Using_Custom_Fields all day, but it doesn't say how to put in the value part.

    This is what I have so far for the custom key:
    <ul class='postmetadata'> <span class='post-meta-key'>Weather:: </span>

    And here it is in my blog, not yet public: http://donnabarstow.com/cartoons/

    I think I need to add a $ or go_get or a ? for the value, but I cannot figure out the language that I should use here.

    Can anyone please help?

    (I will be making up the weather myself, since it is so totally boring here in LA, and the weather rarely changes.)

  2. Drawer
    Member
    Posted 5 years ago #

    Another day lost to hunting everywhere for this answer. Really, WordPress has terrible terrible support. I feel so sorry for new bloggers who think they can just jump into this.

    Anyway, let me try to help someone else. The page I linked to above in Codex doesn't have this anywhere in the page. Yes, you can use the simple formula,
    <?php the_meta(); ?>
    by just putting it somewhere in your index page where the metadata is, and it works well. (I was wrong, didn't think it would work!) However, it is ONLY in list form, with an indent and a bullet point. I couldn't find any other templates anywhere, and I think it's unlikely that the bullet point at the bottom of the post would match most themes. I didn't want it like that.

    So here is exactly what I put in my index theme file:
    <ul class="postmetadata"> <span class='post-meta-key'>Weather:: <?php $key=Weather; echo get_post_meta($post->ID, 'Weather', true); ?> </span>

    That's it. I put the postmetadata part in so the style would match the other metadata for my tags.

    I hope this helps someone else!

  3. Drawer
    Member
    Posted 5 years ago #

    PS. I should add that I cobbled this together from many different answers here on the forum.

    Just trial and error. There must be a better way to build a blog.

  4. jrgd
    Member
    Posted 5 years ago #

    I don't know if you're still searching for this but this might be useful to someone else as well; it essentially does the same thing as the_meta() but you can have a bit more control (like hiding some of the custom field or using keys and values in php):

    <?php 
    
        $keys = get_post_custom_keys($post->ID); 
    
        foreach($keys as $key) {
            $value = get_post_meta($post->ID, $key, 'true');
            if($key != "pp_item" AND $key!="currency" AND $key!="_edit_last" AND $key!="_edit_lock" AND $key!="_wp_page_template" AND $key!="email_item_name" && $key!="email_register_for_later") {
                if ($key=="pp_amount") $key = 'price';
                if ($key=="email_amount") $key= 'approximate price';
            echo "$key: <a href='?s=$value&key=$key'>$value</a><br />";
            }
        }
    
    ?>

    and for the trial and error process: that's what i'm doing each and every day, and i happen to like it a lot :)

Topic Closed

This topic has been closed to new replies.

About this Topic