简体   繁体   中英

ACF - page selector get custom field as well

I am using Advanced Custom Fields and have chosen 'Page Selector' that allows me to choose pages.

On the front end, I am able to code it so that the pages I've chosen are on the home page with the title and page link but I'm also trying to pull through a custom field in that page as well.

Here is that code I have so far;

<?php if( have_rows('page_selector') ):
$i=1;
$count = (count($my_fields['value']));
?>          
<?php while( have_rows('page_selector') ): the_row(); 
    // vars
    $page = get_sub_field('page');
?>  
    <div class="lg-col-6 md-col-6">
        <div class="sub_service">

            <?php 
            // vars
            $post_id = get_sub_field('page', false, false);

            // check 
            if( $post_id ): ?>
            <a href="<?php echo get_the_permalink($post_id); ?>"><h2><?php echo get_the_title($post_id); ?></h2></a>

            <?php endif; ?>

            //This is the custom field
            <?php get_sub_field('description'); ?>

        </div>
    </div>                          
<?php
    $i++;
    endwhile; ?>
<?php endif; ?> 
<?php wp_reset_query(); ?>

Apologies in advance if it doesn't make sense, will try and explain further if it's confusing.

Thanks

您发布问题,然后答案就来了...

<?php the_field('description', $post_id); ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM