AnswerBun.com

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

WordPress Development Asked by Gande on December 13, 2020

I am using WP_Query to loop a Custom Field, Custom Post Type that shows 6 Menu Icons across 6 horizontal fields. The icons do not show on the page.

My query code is:

<?php $loop = new WP_Query( array( 'post_type' => 'course_feature', 'orderby', => 'post_id', 'order' => 'ASC')); ?>

code to show loop:

<?php while( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="col-sm-2">
<i class=<?php the_field('course_feature_icon'); ?>"</i>
</div>

<?php endwhile; ?> 

2 Answers

The icons still do not show. The course_features titles that appear beneath each icon shows, but the icons do not show.

So, I have 6 columns of text, but the icons do not appear above the text. Not sure what to do … I tried the suggested edits. The icons do not show.

I have them as a custom field group: course_feature_icon, field type: Radio button, choices: .ci ci-computer, and 5 additional names. (css icon sprite name).

Answered by Gande on December 13, 2020

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>

Answered by Jacob Peattie on December 13, 2020

Add your own answers!

Related Questions

add shortcode support in customizer

1  Asked on November 16, 2021 by maheshwaghmare

     

How to allow duplicate comments?

1  Asked on November 14, 2021 by lumi

 

Open the attachment details modal

1  Asked on November 11, 2021 by syntacular

     

custom post type category count shortcode

2  Asked on November 11, 2021 by northtime

       

How to add classes to post_class?

2  Asked on November 11, 2021 by antonino-lattene

 

How to do string attachment with wp_mail

3  Asked on November 11, 2021 by nicautre

       

WP REST API not retrieving all categories

1  Asked on November 11, 2021 by abhivemp

     

jQuery UI Accordion loading very slow

0  Asked on November 11, 2021 by bluedimensional

   

Adding a WordPress Admin Dashboard to my local wordpress site

0  Asked on November 11, 2021 by stuart-kushner

   

How to break meta values into different items and avoid duplicates?

1  Asked on November 11, 2021 by artist-learning-to-code

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP