Waqas Ali
Waqas Ali

Reputation: 11

ACF not displaying sub field

Hi guys I am using ACF pro with Repeater addon and custom Post type UI Plugin.

I created Custom post type "course library" and there I added few fields and sub field using repeater

first field is main heading field name main_heading "which is currently displaying"

the second is "Your topic title 1" field name "your_title_field_1" and using repeater which has field label "list" and and field name "list_items" which is not displaying anything

here is my code

<div class="container">
<div class="row featured-boxes">
<?php $loop = new WP_Query( array( 'post_type' => 'course_library', 'orderby' => 'post_id', 'order' => 'ASC')); ?>
<?php while ($loop->have_posts() ) : $loop->the_post(); ?>
<div class="col-md-3">
<div style="height: 2572px;" class="featured-box">
<h4><?php echo the_field('main_heading'); ?></h4>
<ul class="menu" id="java_technologies">
<li><a target="_top" href="/"><?php echo the_sub_field('list_items'); ?></a></li>
</ul>
</div>
</div>
<?php endwhile; ?>

please help to fix this and I can display my list items too.

Upvotes: 0

Views: 1000

Answers (2)

Wouter Groenewold
Wouter Groenewold

Reputation: 1

Also the <h4><?php echo the_field('main_heading'); ?></h4> is quite ugly cause it echo's two times (the_field() echo's, get_field() returns) so I would change that one as well if I was you

Upvotes: 0

user4094161
user4094161

Reputation:

Try this

<div class="container">
<div class="row featured-boxes">
<?php $loop = new WP_Query( array( 'post_type' => 'course_library', 'orderby' => 'post_id', 'order' => 'ASC')); ?>
<?php while ($loop->have_posts() ) : $loop->the_post(); ?>
<div class="col-md-3">
<div style="height: 2572px;" class="featured-box">
<h4><?php echo the_field('main_heading'); ?></h4>
<?php $your_topics = get_field('your_topic_title_1'); ?>
<ul class="menu" id="java_technologies">
<?php foreach($your_topics as $your_topic) { ?>
      <li><a target="_top" href="/"><?php echo $your_topic['list_items']; ?></a></li>
<?php } ?>
</ul>
</div>
</div>
<?php endwhile; ?>

Upvotes: 1

Related Questions