Your the_field() function echo the output, not returning the value as
@KIKOSoftware speculated. If it wouldn’t echo and returned value instead, you’d end up with an empty <p> tag anyway, because there is no echo to output the result in your code.
If the_field() returned value, you’d need
use either
<?php echo the_field('price',$postID) ; ?>
or
<?=the_field('price',$postID) ; ?>
So the answer is: check your the_field() function.
Using the_field() echos and get_field() returns the value of a specific field. So with your provided code if you change both to get_field() then it will display empty <p> tags as you’re not echoing them.
The solution will be to change the if condition to get_field() and the one inside <p> tags would remain the_field().
3
Answers
Your
the_field()
functionecho
the output, not returning the value as@KIKOSoftware speculated. If it wouldn’t
echo
and returned value instead, you’d end up with an empty<p>
tag anyway, because there is noecho
to output the result in your code.If
the_field()
returned value, you’d needuse either
or
So the answer is: check your
the_field()
function.Just change
By
And Enjoy!
Using the_field() echos and get_field() returns the value of a specific field. So with your provided code if you change both to
get_field()
then it will display empty<p>
tags as you’re not echoing them.The solution will be to change the if condition to
get_field()
and the one inside<p>
tags would remainthe_field()
.If you ever echo any tags then
get_field()
should be used.Any function that echos its value should not be used inside if statement’s
(condition)
.