WP_Query to loop a Custom Field, Custom Post Types do not show

There’s a missing opening quote and closing bracket on this line:

<i class=<?php the_field('course_feature_icon'); ?>"</i>

Needs to be:

<i class="<?php the_field('course_feature_icon'); ?>"></i>

That’s all that’s wrong with your code. It should then work assuming:

  1. You have a custom field, course_feature_icon, whose value is a valid CSS class.
  2. You have the necessary CSS to add an icon based on that class.

One last suggestion though. For safety you should escape the field value before outputting it as a class:

<i class="<?php echo esc_attr( get_field('course_feature_icon') ); ?>"></i>

Leave a Comment