CPT url not working in MB View
- This topic has 8 replies, 3 voices, and was last updated 4 years, 6 months ago by
[email protected].
-
AuthorPosts
-
May 16, 2021 at 1:06 PM #28211
Shrini
ParticipantWould like to display list of candidates & its link
if any one click on the candidates it should land their CPT page
but I couldnt pull those candidate url
here is my code{% set candi = {post_type: 'candidate', posts_per_page: 5} %}
{% set candidates = mb.get_posts( candi ) %}{% for candidate in candidates %} <br/>
1. Candidate url: {{ post.url }} <br/>
2. {{ candidate.url}} <br/>
3. {{ candidate.post_title }} <br/>
{% endfor %}May 16, 2021 at 1:10 PM #28212Shrini
ParticipantMay 16, 2021 at 1:14 PM #28213Shrini
Participant<div>
{% set candi = {post_type: 'candidate', posts_per_page: 5} %}
{% set candidates = mb.get_posts( candi ) %}{% for candidate in candidates %} <br/>
1. Candidate Name: {{ candidate.post_title }} <br/>
2. Candidate Link: {{ post.url }} <br/> // displays only current post url
3. Candidate Link: {{ candidate.url}} <br/>
{% endfor %}</div>
May 16, 2021 at 1:15 PM #28214Shrini
Participant{% set candi = {post_type: 'candidate', posts_per_page: 5} %} {% set candidates = mb.get_posts( candi ) %} {% for candidate in candidates %} <br/> 1. Candidate Name: {{ candidate.post_title }} <br/> 2. Candidate Link: {{ post.url }} <br/> // displays only current post url 3. Candidate Link: {{ candidate.url}} <br/> {% endfor %}May 16, 2021 at 4:37 PM #28218Long Nguyen
ModeratorHi,
candidateis a post object so if you want to get the post URL, you can use the WordPress function get_the_permalink()2. Candidate Link: {{ mb.get_the_permalink( candidate.ID ) }} <br/>The fields in the list Insert Fields would not work if you use the custom query (get_posts). Use the WordPress functions base on the post ID instead.
May 16, 2021 at 8:04 PM #28220Shrini
ParticipantThank you
May 19, 2021 at 7:54 PM #28291[email protected]
ParticipantHi,
Thx for this answer.
In my case, my URL is not clickable when I insert URL field.
How to fix it please ?
Thx,
OliverMay 19, 2021 at 10:10 PM #28303Long Nguyen
ModeratorHi Oliver,
You can use a
<a>tag to show a link and assign the URL field to thehrefattribute. Just like:<a href="{{ post.url }}">{{ post.url }}</a>May 19, 2021 at 10:41 PM #28305[email protected]
ParticipantOff course !
Thx a lot Long 😉 -
AuthorPosts
- You must be logged in to reply to this topic.