0
votes

I have an ACF field for my Custom Post "Services" in which it has ACF fields for "is featured service" checkbox and "featured url" fields. If a user check that field, it means its a featured service and he can fill the featured url field and it is working fine on single page, but I do need to call it on homepage to show my featured services on home page. My code on home page is as follows:

<div class="service-box"> 
    <?php if(has_post_thumbnail($service)): ?>
    <a href="<?php the_field('featured_url'); ?>"><img src="<?php echo get_the_post_thumbnail_url($service); ?>" alt="<?php echo $service->post_title; ?>"></a>
     <?php endif; ?>
     <div class="service-info">
     <h3><a href="<?php the_field('featured_url'); ?>"><?php echo $service->post_title; ?></a></h3> 
     <p><?php echo substr($service->post_content, 0, 70). (strlen($service->post_content)>70?'...':'') ?></p>
     <a class="btn-rounded" href="<?php the_field('featured_url'); ?>"></a>
     </div>
</div>

How can I get the "featured url" field on my home page?

1

1 Answers

2
votes

Maybe there are some conflicts with the WP Query. As you are looping the services on the home page, obviously you are getting the service id. So please try to use this syntax the_field('featured_url', $service_id) hope this will resolve your query.