skip to Main Content

I’m trying to display the data of a ACF but I’m getting this error in Visual Studio Code:

enter image description here

This is the entire code. I tried reinstalling the plugin, added PHP to the path but nothing seems to be working.

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(); ?>

3

Answers


  1. In the intelephense, make sure you add wordpress to the list.

    enter image description here

    Login or Signup to reply.
  2. On top of what @DaleNguyen adviced above…

    Make sure the directory that contains acf plugin is in your Vs Code. Example, instead of only opening the theme directory in Vs Code in which you are probably working, open the entire wp_content directory in your VS Code. That way, when intelephence run in the back-ground, it will be able to reach the plugins folder and acf functions in the acf plugin folder.

    Login or Signup to reply.
  3. @james-serengia answered with one working solution that the ACF plugin folder should be open in the same workspace as the code you are working on and the warning disappears.

    Alternatively if that is inconvenient, you can add you can add the ACF stubs to VSCode. It is a bit of messing around but when it is done, it is done. See this explanation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search