I am using cmb2 to create the custom post type, and I have a custom post type called legacy_cycle, which contains several wysiwyg fileds.
Than I am using Timber as theme tool to display the input. However, the wysiwyg field could not work properly. It is fine if it only contains text or image, but it only output the following information when I insert a youtube video in the wysiwyg editor under the custom post type, but the output from the native wordpress editor is fine.
" https://www.youtube.com/watch?v=MS91knuzoOA"
I tried to use post.get_filed(‘my_wysiwig’), but it did not work.
I am wondering how I could output the field correctly? much appreciated!
So, I figured it out through this post..Applying oembed filters to WYSIWYG field
My solution by using timber/twig is to get the data in the single.php, and here is the code:
Then I can print the video in the single-custom-post-type.twig by using {{post.my_wysiswyg}}
It looks like you just need to process shortcodes in that field. This should convert those into actual YouTube videos:
I use CMB2 extensively with Timber and my usual approach is to extend
TimberPost
and add in methods for getting meta data. For a wysiwyg field, something like this:You can specify which class Timber will use with the second parameter of
Timber::get_posts