Visual Studio Code 中未定义的函数 the_field

Lir*_*epi 4 php wordpress visual-studio-code

我正在尝试显示 ACF 的数据,但在 Visual Studio Code 中收到此错误:

在此输入图像描述

这是整个代码。我尝试重新安装插件,将 PHP 添加到路径中,但似乎没有任何效果。

Single.php
<?php get_header();?>

    <div class="container">

        <div class="row">
            <div>

            <img src="<?php the_post_thumbnail_url('thumbnail'); ?>" id="single_header">


                        <div id="single_content">
                            <?php if (have_posts()):while (have_posts()):the_post(); ?>
                                <?php 
                                    $fn=get_the_author_meta('first_name');
                                    $lname=get_the_author_meta('last_name');
                                    $email=get_the_author_meta('email');
                                ?>

                                    <h1 class="text=cenetr nt-3 mb-5 text-primary"><?php the_title();?></h1>
                                    <small>Publishor:<?php echo $fn; ?></small>

                                        <p><?php the_content();?></p>

                                    <?php
                                            endwhile;
                                        endif;

                                    ?>

                                    <?php previous_post_link(); ?>
                                    <?php next_post_link(); ?>
                        </div>

                        <div id="single_extraInfo"> 
                            <p>Company: <?php the_field('flight_company'); ?></p>
                            <p>Date: <?php the_field('flight_date'); ?></p>
                            <p>Capacity: <?php the_field('flight_capacity'); ?></p>

                        </div>
            </div>


    
        </div>
    </div>

    <?php get_footer(); ?>

Run Code Online (Sandbox Code Playgroud)

小智 7

除了上面@DaleNguyen 的建议之外......

确保包含acf 插件的目录位于您的Vs Code中。例如,不要只打开您可能正在使用的 VS Code 中的主题目录,而是在 VS Code 中打开整个wp_content目录。这样,当 intelephence 在后台运行时,它将能够访问插件文件夹和acf 插件文件夹中的acf 函数


Dal*_*yen 5

在 中intelephense,确保您添加wordpress到列表中。

在此输入图像描述

  • the_field() 不是一个 wordpress 函数,而是一个 AdvancedCustomFields 插件函数,因此添加“wordpress”并没有什么效果,遗憾的是,但如果您使用 ACF,无论如何都应该添加,因为您无疑在同一项目中使用其他 WordPress 函数 (3认同)
  • 是的,但错误仍然显示,代码正在运行,所以一切都很好,谢谢 (2认同)