WordPress查询找不到自定义字段中的数据?

时间:2018-07-25 13:49:15

标签: php wordpress

我为主页设置了一个自定义字段组(在页面下找到)。我试图像这样提取数据:

home.php

// query to fetch data from page
$argsOverview = array('post_type' => 'pages' );
$getOverviewPage = new WP_Query($argsOverview);

if ($getOverviewPage->have_posts() ) {

            tp_get_part( 'templates/snippets/section-two-overview.php',
                array(
                    'overviewHeading'          => get_field('overview_heading'),
                    'overviewSubheading'       => get_field('overview_subheading'),
                    'overviewText'             => get_field('overview_text'),
                    'overviewBackground'       => get_field('background_color'),
                    )
                );

            echo $overviewHeading;
} else {
    echo "test";
}

section-two-overview.php

<div class="overview-container" style="background-color: <?php echo $overviewBackground; ?>">
        <div class="overview-wrapper">
            <p>test</p>
            <h3><?php echo $overviewHeading; ?></h3>
            <h1><?php echo $overvewSubheading; ?></h1>
            <p><?php echo $overviewText; ?></p>
        </div> 
</div>

但是,它不显示 section-two-overview.php 中的内容吗? tp_get_part() 是一个自定义函数,可在其他地方使用。但是,当从页面而不是自定义帖子类型中提取数据时,它不会执行。

当前,它显示echo "test",表示如果失败,不确定为什么吗?

1 个答案:

答案 0 :(得分:0)

请在您的查询中尝试使用'post_type'=>'page',看看它是否有效。 https://codex.wordpress.org/Post_Types