WordPress.org

Forums

Adding Custom Fields (13 posts)

  1. Anonymous
    Unregistered
    Posted 12 years ago #

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

  2. Lilandra
    Member
    Posted 12 years ago #

    what *is* a custom field for?

  3. rpeeck
    Member
    Posted 12 years ago #

    ^^ lol... i was wondering about that too...

  4. Lilandra
    Member
    Posted 12 years ago #

    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!

  5. OperaManiac
    Member
    Posted 12 years ago #

  6. Lilandra
    Member
    Posted 12 years ago #

    thank you

  7. lonney
    Member
    Posted 11 years ago #

    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

  8. nubeli
    Member
    Posted 11 years ago #

    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 { ?>

  9. nubeli
    Member
    Posted 11 years ago #

    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.

  10. gaebe
    Member
    Posted 11 years ago #

    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?

  11. gaebe
    Member
    Posted 11 years ago #

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

  12. serendipity
    Member
    Posted 11 years ago #

    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.

  13. amory
    Member
    Posted 11 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.