页面数组中的自定义字段

时间:2015-06-30 08:16:58

标签: wordpress advanced-custom-fields singlepage

我正在创建单页面布局,我想从ACF添加自定义字段。

<?php $args = array(
    'sort_order' => 'ASC',
    'sort_column' => 'menu_order', //post_title
    'hierarchical' => 1,
    'exclude' => '',
    'child_of' => 0,
    'parent' => -1,
    'exclude_tree' => '',
    'number' => '',
    'offset' => 0,
    'post_type' => 'page',
    'post_status' => 'publish'
);
$pages = get_pages($args);
//start loop
foreach ($pages as $page_data) {
    $content = apply_filters('the_content', $page_data->post_content);
    $title = $page_data->post_title;
    $slug = $page_data->post_name;
?>


<div id='<?php echo "$slug" ?>' class="section">

<div id="inner-content" class="wrap cf">
    <div id="main" class="m-all cf" role="main">
        <div class="content">
            <h2 class="section-title"><?php echo "$title" ?></h2>
                <?php echo "$content" ?>
        </div>             

        <div class="thumb">
            <?php echo get_the_post_thumbnail( $page_data->ID, 'thumb-page' ); ?> 
        </div>
    </div>
</div>


    

这是代码。如果为ACF添加常规代码(它没有显示。(我有两个不同的自定义字段,但只有一个,'详细信息',需要包含在循环中)。

谢谢!

1 个答案:

答案 0 :(得分:1)

由于您使用的是自定义foreach循环(而不是默认的WP循环),因此您需要将帖子ID传递给ACF函数:

<?php the_field('details', $page_data->ID) ?>