Support Forum
Would 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 %}
<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>
{% 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 %}
Hi,
candidate
is 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.
Thank you
Hi,
Thx for this answer.
In my case, my URL is not clickable when I insert URL field.
How to fix it please ?
Thx,
Oliver
Hi Oliver,
You can use a <a>
tag to show a link and assign the URL field to the href
attribute. Just like:
<a href="{{ post.url }}">{{ post.url }}</a>
Off course !
Thx a lot Long 😉