Display Custom Field Label
-
I love this plugin due to the simplicity and it’s powerful too.
I made whole bunch of custom fields for a certain kind of post type. I display them using conditional div, only display the div containing the custom field value if the value is exist.
Right now, I do it manually using this code:
<?php $konten = get_post_meta($post->ID, 'objective', true); if($konten != '') { ?> <div class="field_label">Objective:</div> <div class="field_value"> <?php echo nl2br($konten); ?> </div> <?php } ?>
I have almost zero PHP skill. That code I stole somewehere on the internet ??
My question is, since I have like 20 custom fields, I feel like it’s too much if I have to write them one by one. I am sure there’s a way to use one PHP function to display all the custom field on the post conditionally.I am thinking of using
foreach
function. Can anybody help me on how to do that, please?
I get confused because I need to pull thefield label
too, because on my code above, I type it manually. How do I display the field label automatically?Thank you very very much
https://www.ads-software.com/extend/plugins/custom-content-type-manager/
- The topic ‘Display Custom Field Label’ is closed to new replies.