-1

I have a wordpress site using a twig template. I'm trying to call and display a custom field.

How can I do this?

cigien
  • 57,834
  • 11
  • 73
  • 112
tine
  • 11
  • 6

1 Answers1

0

You can call wpcf values easily with post.get_field().

Ex:

{{post.get_field('wpcf-ticket-url')}}

Also you may create any helper functions to extend your twig library. You can assign them on functions.php file in your twig theme folder.

Ex:

twig-theme/functions.php:

$context['get_custom_meta'] = TimberHelper::function_wrapper( 'get_custom_meta', array('',0) );//array contains default values

function get_custom_meta($key,$id){
    if(empty($id)){
       return types_render_field($key,  array("raw"=>"true","separator"=>";"));
    }else{
       return get_post_meta( $id, 'wpcf-'.$key, true );
    }
}

twig-theme/views/xxx.twig :

{{ get_custom_meta("ticket-url",item.object_id) }}
Salt Hareket
  • 764
  • 7
  • 18