Support » Fixing WordPress » Adding Custom Fields

  • How do you add a Custom Field field into your template? What is the code you use?
    Thanks 🙂

Viewing 12 replies - 1 through 12 (of 12 total)
  • what *is* a custom field for?

    ^^ lol… i was wondering about that too…

    maybe it’s like you can define a field called mood or music or breakfast?
    and use those instead of the hacks?
    hmmmm
    must experiment, in June
    and i’mglad it’s not just me!

    thank you

    Hi, I’m still a bit lost with this, I’m thinking about switching to WP for my blog.
    I’m travelling at the moment, and I want to have a location (county & place ) entry, that defaults to the last location posted from.
    I’m lost as to how to make this field, (the information isnt very clear on how to do this) add it to the write page, and to the template. Also in the template have it build a list of menu/links so for example someone can view all the posts I made from England and or more specific London.
    Any pointers to info on how best to do this would be great 🙂
    Lonney

    I’m not sure how you can get it to default to the last location. But it is pretty easy to create a key called “Location” and then to add a key/value to each post. For example, a new post allows you to choose a set key (like “Location”) and then put a value (“Istanbul”). Or you can add a new key like “Fruit” and value “Apple”.
    Then to get it to appear in the post, the most basic way is to use the_meta tag:
    ?php the_meta(); ?>
    within The Loop.
    The Loop is everything in your index.php (or other template file) between:
    <?php if ($posts) { foreach ($posts as $post) { start_wp(); ?>
    and
    <?php } } else { ?>

    Lonney, it is probably a lot easier if you just use Categories to create your menu links. Since you can create hierarchical categories you could have England>London, Bath, …. and it would all appear in the menu.
    It’s possible to create menu links using the custom fields, but not simple. Although you could fiddle around with the get_custom plugin. I haven’t tried it.

    I still don’t get it very well. I want to create a custom field “current mood” for all of my entries. How do I make the field automatically appear in the write page (post.php) so that I can directly enter the values?

    And can someone tell me how to edit the appearance of the field on the blog?

    OK, the first request requires a bit of editing in edit-form/edif-form-advanced.php (to create a form field to enter the custom field) plus post.php . For example (untested!! I just copied some edits I made that work for me):
    In edit-form-advanced.php —

    <fieldset class="mooddiv">
    <legend><?php _e('Mood') ?></legend>
    <div><input type="text" name="my_mood" size="3"
    tabindex="2" id="my_mood" /></div>
    </fieldset>

    + adjust tabindex, css for .mooddiv.
    In post.php / editpost section —

    if(isset($_POST['my_mood']))
    {
    $_POST['metakeyselect'] = 'my_mood';
    $_POST['metavalue'] = $_POST['my_mood'];
    add_meta($post_ID);
    }

    For the second, I’d recommend using coffee3code’s get custom field values plugin.

    amory

    (@amory)

    serendipity where does the second part go in post.php?

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Adding Custom Fields’ is closed to new replies.