简体   繁体   English

ACF-页面选择器也获得自定义字段

[英]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); ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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