Undefined function the_field in Visual Studio Code - php

I'm trying to display the data of a ACF but I'm getting this error in Visual Studio Code:
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(); ?>

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.

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

#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.

Related

Wordpress blog theme modification

I am using Primal wordpress theme for the purpose of a simple blogging website.
I want to make a minor change on the home page. I want to remove the "Date, user and comment" line displayed below the title of the each post. I am not able to remove that from the dashboard. Kindly suggest solution. Suggest steps if it requires plug-in modifications.
I want to remove text highlighted in yellow
go to your \wp-content\themes\primal\template-parts\content-single.php
then find the code and comment it
<!--div class="entry-meta">
<span class="date-structure">
<span class="dd"><i class="fa fa-calendar"></i><?php the_time(get_option('date_format')); ?></span>
</span>
<?php primal_author(); ?>
<?php primal_comments_meta(); ?>
<?php primal_edit() ?>
</div--><!-- .entry-meta -->
then save the file
It will work for you.
Thanks

PHPStorm >> Reforrmat code deletes PHP code

I am using PHPStorm with mix HTML/PHP..
My codes are
<div id="tab2" class="display-none">
<?php include_once "profile/permissions.php"; ?>
</div>
When I use Ctrl+Alt+L for Reformat code then PHP codes remove auto. How can I stop this.
Codes after Reformat.
<div id="tab2" class="display-none">
</div>
I can't understand PHPStorm's problem.
Strange but problem is solved with this change...
<div id="tab2" class="display-none"><?php include_once "profile/permissions.php"; ?></div>
Just removed lines between <?php and <div id="tab2" class="display-none">

Bad Code given by Developer for Magento Theme

I was given this code by the developer of the magento theme I am using but get an error after placing in the file where I was told to. Can someone please tell me what could be wrong with this code?
<div class="short-description clear">
<div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription();, 'short_description') ?></div>
</div>
There's an extra ; after $_product->getShortDescription() that doesn't belong there. Also there should be another closing bracket after 'short_description'). Change the PHP line to:
<?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription(), 'short_description')); ?>

the_content() for a Wordpress Theme Doesn't Produce <p> Tags

For some reason, the theme I've made won't turn the double newlines (pressing enter in the Visual editor) into paragraph tags. I tried disabling all plugins and it still doesn't work. It does work if I change to a default theme though. Any ideas?
<?php while ( have_posts() ) : the_post(); ?>
<div class="container">
<h2>
<?php the_title(); ?>
</h2>
</div> <!-- /container -->
<div class="container contentArea">
<?php the_content(); ?>
</div>
<?php endwhile; // end of the loop. ?>
I think that's done by the wpautop function (see here), which I thought was enabled by default (see here).
Perhaps you could add it manually to your theme? Or better, work out why it's not being enabled.

Trouble showing images in other pages than Home (wordpress/html/css)

Hi I have a small website im doing for a customer and I have used a html/css-site and transferred it to wordpress by using blank theme. So far so good, have a look at energyshop.se if u want and in startpage the top two images are shown, but not udner the rest of the tabs - why? I add the images in the header.php so it should find them on all tabs...?
//header.php
<body <?php body_class(); ?>>
<div id="container">
<div id="header" onclick="location.href='http://www.energyshop.se/';" style="cursor: pointer;">
<h1><?php bloginfo('name'); ?></h1>
<div class="description"><?php bloginfo('description'); ?></div>
</div>
<div id="main_menu">
<?php wp_nav_menu(); ?>
</div>
This is because you're using relative paths. When creating a WordPress theme and you want to load resources from your theme, you should use absolute paths. There are two template tags that make this easy for you: get_bloginfo() and bloginfo(). The first one returns the value, and the second one echoes the value(that you request via the first argument passed to the function).
So in order to display an image, you should have:
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/icon_en_global.png" alt="English.png">
This will always result in this(for your site):
<img src="http://energyshop.se/wp-content/themes/blank/images/icon_en_global.png" alt="English.png">
So simply replace all wp-content/themes/blank with <?php bloginfo('stylesheet_directory'); ?>.

Categories