• Resolved Samar Hatem

    (@samar-hatem)


    Hi, I have 2 questions ??
    first one is: is it possible to make different templates for single post displaying?
    second and most important one: I was editing a ready made theme and I had to create custom fields for nutritional facts, in my test I created only 3 fields and as I saw I should declare each one in my code like that:

    <div>
            <span class="item">Protein</span>
            <span class="value"><?php echo get_post_meta($post->ID, 'Protein',true); ?></span>
        </div>
        <div>
            <span class="item">Sodium</span>
            <span class="value"><?php echo get_post_meta($post->ID, 'Sodium',true); ?></span>
        </div>
        <div>
            <span class="item">Sugars</span>
            <span class="value"><?php echo get_post_meta($post->ID, 'Sugars',true); ?></span>
        </div>

    but what if the admin wanted to add an extra field, say Cholesterol?
    how can I make it responsive to each field the admin add? how to make it able to add every new field automatically?
    I though there might be a loop which loops through these meta data and echo them out automatically without having to declare each one of them, it is possible?
    thanks in advance..

  • The topic ‘Custom fields’ is closed to new replies.