Custom Fields in agenda-widget.twig
-
I have a custom field that I want to display on the event page as well as in the widget.
I have managed to get the field to display in event-single.twig by creating a filter in functions.php
add_filter( 'ai1ec_theme_args_event-single.twig', 'get_room', 10, 2 ); function get_room( $args, $is_admin ) { $post_id = $args['event']->get( 'post_id' ); $args['custom_room_field'] = get_post_meta( $post_id, 'Room', true ); return $args; }
I then simply use
{{ custom_room_field }}
in event-single.twig and it displays as expected.However if I try to get the same field showing in my agenda-widget.twig it does not work.
I created a similar filter in functions.php (see below)
add_filter( 'ai1ec_theme_args_agenda-widget.twig', 'widget_get_room', 10, 2 ); function widget_get_room( $args, $is_admin ) { $post_id = $args['event']->get( 'post_id' ); $args['widget_custom_room_field'] = get_post_meta( $post_id, 'Room', true ); return $args; }
But this does not work, and after testing it this is because the post_id that I get in the first filter is not passed to this filter.
How can I get the post_id from within the functions.php file or how can I pass it from the agenda-widget.twig file.
- The topic ‘Custom Fields in agenda-widget.twig’ is closed to new replies.