0

I'm using Wordpress with the "Advanced Custom Fields" plugin, and I'm trying to call variables from the plugin into my TWIG file.

The documentation for the plugin says to use <?php the_field('field_name'); ?> in the PHP, but I can't figure out how to translate that code to TWIG.

I tried the following:

  • Running code as is (but it appears TWIG doesn't run pure PHP.)
  • {% post.the_field('my_fields_name') %}, but to no avail
  • {{ post.my_fields_name }}, but it printed/logged "Array" to the frontend.
  • {{ post.get_field('the_field', my_fields_name) }} and {{ post.get_field('the_field', 'my_fields_name') }}

Any help will be greatly appreciated

CSS Apprentice
  • 899
  • 1
  • 16
  • 29
  • 2
    [This](http://stackoverflow.com/a/18667961/2518525) is worth a read. Basically states that you can't call php function directly, however you can write extensions of TWIG to do this – Darren Feb 24 '17 at 04:22

1 Answers1

0

Took me a while, but ended up being an easy solution! Turns out these custom fields are stored in the meta-data, so all I had to do was {{ post.meta('my_fields_name') }}

CSS Apprentice
  • 899
  • 1
  • 16
  • 29