get_field不预先提供自定义字段的输出

这是我的代码,但是没有给出任何输入


    <?php
        if(get_field('header'))
        {
    ?>
    <div class="about-us">
        <div class="--header">  
            <img src="<?php echo get_template_directory_uri()?>/assets/images/laptop.jpg" alt="">
            <div class="content">

                <?php echo '<h2>' . the_field('heading') . '</h2>';
                echo '<h4>' . get_field('description') . '</h4>';?>
            </div>
        </div>
    </div>
    <?php
        }

    ?>

This is my custom filed that i created

yys19024 回答:get_field不预先提供自定义字段的输出

the_field函数回显的值。因此您不必在其他回显功能中使用它

请尝试这段代码,让我知道它是否有效。

<?php
if ( get_field('header') ){
    ?>
    <div class="about-us">
        <div class="--header">
            <img src="<?php echo get_template_directory_uri() ?>/assets/images/laptop.jpg" alt="">
            <div class="content">

                <?php echo '<h2>' . get_field('heading') . '</h2>';
                echo '<h4>' . get_field('description') . '</h4>'; ?>
            </div>
        </div>
    </div>
    <?php
}else{
    _e('the field header not founded','textdomain');
?>
,

如果您仍然没有从ACF中获得价值,那么您应该像下面这样获得价值:

<?php
  $post_id = false; // current post
  $post_id = 1; // post ID = 1
  $post_id = "user_2"; // user ID = 2
  $post_id = "category_3"; // category term ID = 3
  $post_id = "event_4"; // event (custom taxonomy) term ID = 4
  $post_id = "option"; // options page
  $post_id = "options"; // same as above

  echo $value = get_field( 'my_field',$post_id );
?>

我希望它能对您有所帮助。 谢谢

,

您写错了条件。 header没有字段,它只是创建了所有自定义字段的一个组。您可以在自定义字段中指定条件。

因此,您需要编写这样的条件。

<?php
    if( get_field( 'heading' ) ) {
        // Your Code
    }
?>
本文链接:https://www.f2er.com/2919440.html

大家都在问