Displaying shortcodes in title or other fields
- This topic has 4 replies, 2 voices, and was last updated 2 years, 10 months ago by
Long Nguyen.
-
AuthorPosts
-
June 20, 2022 at 6:36 PM #36590
Chris P
ParticipantHi Long,
I am using shortcodes in my titles and they get rendered well but not in my mb views loop of these custom post types.
See code below
The {{ post.post_title }} doesn't get displayed when it contains a shortcode. How can I force it to be rendered before displaying it?I tried this
{% set title = mb.rwmb_meta( 'post_title', '', post.ID ) %}and then displaying title but that doesn't work
{% set args = { post_type: 'colour', posts_per_page: -1, tax_query: [{ taxonomy: 'colour-category', field: 'slug', terms: term.slug }], orderby:'meta_value', meta_key:'number_colorsort',order:'asc' } %} {% set posts = mb.get_posts( args ) %} {% for post in posts %} {% set link = mb.get_permalink( post.ID ) %} {% set image = mb.rwmb_meta( 'single_image_example', '', post.ID ) %} <li class="jaga-card col-sm-12 col-md-6 col-lg-3"> <div style="filter:drop-shadow(1px 1px 5px rgba(150, 150, 150, 0.1));"> <a href="{{ link }}" style="background-color:{{ post.color_8sd14s85jps }}; background-image: url('{{ image.full_url}}'); back-ground-position: cover; display:inline-block;clip-path: polygon(0% 0%, 100% 0, 100% 82%, 82% 100%, 0% 100%);; aspect-ratio: 1 / 1; " class="jaga-card-color {{ post.select_texture.value }}"> </a> </div> <a href="{{ link }}"> <div class="jaga-card-title"> <h3>{{ post.post_title }}</h3> <div class="jaga-card-info"> <p>{% if post.text_e4vmtr5xoiu %} Jaga ordercode: {{ post.text_e4vmtr5xoiu }}{% endif %} </p> <p>{% if post.text_bqbm97qew8 %} Colourcode: {{ post.text_bqbm97qew8 }}{% endif %} </p> </div> </div> </a> </li> {% endfor %}
June 20, 2022 at 9:35 PM #36591Chris P
ParticipantIn anoither view where I just use {{ post-title }} to display the titles it works just fine.
With or without shortcodes being usedJune 21, 2022 at 6:16 AM #36604Long Nguyen
ModeratorHi Chris,
Do other custom fields work? Like
post.text_e4vmtr5xoiu
or
{% set image = mb.rwmb_meta( 'single_image_example', '', post.ID ) %}
Please try to remove other arguments in variable
args
and recheck this issue{% set args = { post_type: 'colour', posts_per_page: -1 %} {% set posts = mb.get_posts( args ) %} {% for post in posts %} Post title: {{ post.post_title }} {% endfor %}
June 21, 2022 at 9:54 PM #36616Chris P
ParticipantThe other fields work so does post.post_title, but only when it isn't populated by a shortcode
Removing the arguments give me the same resultsSo when the post title is 'this is a title' it works and shows up in the loop and everywhere else
but when I enter [CONTENTPREPARE id = "104664"] in the post title field it renders everywhere but not in that loop when using {{ post.post_title }}In another view displaying the title filed with {{ post.title }} works regardless if it's populated by a string or shortcode
June 22, 2022 at 10:35 AM #36624Long Nguyen
ModeratorHi Chris,
Thanks for providing more information.
I do not see that issue on my local site, please check this screen record https://monosnap.com/file/JhCZcm5DtvysJos6ocKGhwipAcDm2G
Steps to reproduce:
1. I create a simple loop to display posts
{% set args = { post_type: 'post', posts_per_page: 5 } %} {% set posts = mb.get_posts( args ) %} {% for post in posts %} Post title: {{ post.post_title }} <br> {% endfor %}
which is a shortcode type
2. I create another View with type shortcode to render the post title based on the parameter
my_post_id
{{ mb.get_the_title( my_post_id ) }}
3. I add the view shortcode 2 to the post title and pass a post ID to it
[mbv name="shortcode" my_post_id=1241]
4. I add the view shortcode 1 to a page to render the list posts with titles and it works as well.
-
AuthorPosts
- You must be logged in to reply to this topic.