I am learning WordPress at the moment and I am working with custom field/post types to see how they work within WordPress.
Here I have a section of code where I can clearly see I am repeating myself in order to spit out the Custom Field Label and the Custom field.
<?php if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?>
<?php $field_name = "about";
$field = get_field_object($field_name);?>
<h5 class="cv-subtitle"><?php echo $field['label'];?></h5>
<p class=""><?php the_field('about'); ?></p>
<?php $field_name = "work_experience";
$field = get_field_object($field_name);?>
<h5 class="cv-subtitle"><?php echo $field['label'];?></h5>
<p class=""><?php the_field('work_experience'); ?></p>
<?php $field_name = "education";
$field = get_field_object($field_name);?>
<h5 class="cv-subtitle"><?php echo $field['label'];?></h5>
<p class=""><?php the_field('education'); ?></p>
<?php $field_name = "skills";
$field = get_field_object($field_name);?>
<h5 class="cv-subtitle"><?php echo $field['label'];?></h5>
<p class=""><?php the_field('skills'); ?></p>
<?php endwhile; endif; wp_reset_postdata(); ?></div>
This is for an "About" page on my portfolio which is displayed in the style of a CV.
I am aware repeating my self in this way is not good practice and understand some sort of loop is needed in order to prevent this.
If anyone could help create this loop or point me in some direction, that would be great.
Thanks