【问题标题】:Undefined function the_field in Visual Studio CodeVisual Studio Code 中未定义的函数 the_field
【发布时间】:2022-07-19 19:34:56
【问题描述】:

我正在尝试显示 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(); ?>

【问题讨论】:

  • 您在 VSCode 中使用的 PHP 扩展 intelephense 对该函数一无所知。
  • 那么我该如何解决这个问题
  • 搜索 inteliphense 站点/git 存储库,他们通常似乎在那里挂着破解修复程序
  • 顺便说一句,它不会停止代码工作,它只是检查器报告
  • 我找不到,你能给我一个 lin 什么的吗

标签: php wordpress visual-studio-code


【解决方案1】:

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

【讨论】:

  • 是的,但是错误仍然显示,代码正在运行,所以一切都很好,谢谢
【解决方案2】:

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

确保包含 acf 插件 的目录在您的 Vs 代码 中。例如,不要只在你可能正在工作的 Vs Code 中打开 theme 目录,而是在你的 VS Code 中打开整个 wp_content 目录。这样,intephence在后台运行时,就可以访问到plugins文件夹和acf plugin文件夹中的acf functions .

【讨论】:

    猜你喜欢
    • 2017-08-09
    • 1970-01-01
    • 1970-01-01
    • 2019-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多