0
votes

I have 2 similar lines of code, the first one works OK but the second is not.

This one works ok and displays the title within the <li></li>

$output .= '<li>' . the_title() . '</li>';

This one returns an empty <li></li> and displays the result on top of the page

$output .= '<li>' . the_field('price') . '</li>';

the_field('price') is a custom wordpress field which i've created by using "Advanced Custom Fields" plugin. Here is the documentation of the plugin on how to output the data http://www.advancedcustomfields.com/resources/field-types/select/

1
what is the_field ? A PHP function ? Where is it declared ? Please give more code (PHP, HTML) in order to give you a better answer - MatRt
Clearly the problem is with the_field(price). You'll need to edit your answer with the declaration of that function to get real help. - JakeParis
Well, the_field is a standard Wordpress function, and the question is tagged as being a Wordpress question... - Matt Browne
Oops, sorry, not a standard Wordpress function, it appears to come from the "Advanced Custom Fields" plugin: advancedcustomfields.com/docs/functions/the_field - Matt Browne
The field could be empty for the current record. - Asad Saeeduddin

1 Answers

4
votes

In your case, perhaps its better to use get_field() instead of the_field().

Here is the difference:

  • get_field() will give you the value.
  • the_field() will print the result directly but return NULL.