• Hi WordPress geniuses,

    I am trying to understand custom fields and have read all I can on them in the wordpress forum and google searching, but I am still unsure how I can use them for the task below:

    Simply, I have the need to display:

    Name: Mr. Dudeman
    Company: Modest company
    Website: https://www.modestcompany.com
    Phone: 555-111-2222

    I want to use custom fields in posts, so if I want to add a new customer, I can just add their details (name, company ..etc) into the custom fields and then in another page, I can list all the posts(customers details) in a loop that will display the posts one at a time like so:

    Name: Mr. Dudeman
    Company: Modest company
    Website: https://www.modestcompany.com
    Phone: 555-111-2222

    Name: Mrs. Awesomeperson
    Company: Small company
    Website: https://www.smallcompany.com
    Phone: 555-211-2222

    Name: Dr. Stein
    Company: Mysterious company
    Website: https://www.mysteriouscompany.com
    Phone: 555-311-2222

    etc….

    Is custom fields the way to go?

    If so, then how can I make a post that is a template so I don’t have to keep adding the custom fields over and over again for each new post.

    Thank you

    James

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    I would use custom fields for this task. If a custom field key is used in one post you can select it under “Custom Fields” when you edit or write a new post. So you don’t have to add the key the next time you write a post.

    Thread Starter antistandard

    (@antistandard)

    Thanks Keesiemeijer.

    Also, where is the simplest instructions for using custom fields in wordpress without a plugin please. Some instructions that simply outline the most basic of ways to just add custom field calls into a wordpress page.

    Thank you

    James

    Moderator keesiemeijer

    (@keesiemeijer)

    You can use a loop like this:

    <?php
    // get all posts with a custom field key "name"
    query_posts('meta_key=name'); ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php
    $name = get_post_meta($post->ID, 'name', true);
    echo 'name: '.$name;
    $company = get_post_meta($post->ID, 'company', true);
    if($company != ''){ echo 'company: '.$company; }
    $website = get_post_meta($post->ID, 'website', true);
    if($website != ''){ echo 'website: '.$website; }
    $phone = get_post_meta($post->ID, 'phone', true);
    if($phone != ''){ echo 'phone: '.$phone; }
    ?>
    <?php endwhile; ?>
    <?php endif; ?>

    Thread Starter antistandard

    (@antistandard)

    Thanks mate, I’ll look at this later this weekend and let you know how I go.

    Thanks again for your time,

    James

    Thread Starter antistandard

    (@antistandard)

    Hi Keesiemeijer,

    Yes, that worked, thank you very much.

    I didn’t need the lines:
    // get all posts with a custom field key “name”
    query_posts(‘meta_key=name’); ?>

    but everything else was perfect.

    James

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom fields used like variables’ is closed to new replies.