Custom Fields
Re-Envisioned
Support MB Views CPT url not working in MB View

  • Creator
    Topic
  • #28211
    Resolved Shrini
    Participant

    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 %}

Viewing 8 replies - 1 through 8 (of 8 total)
  • Author
    Replies
  • #28212
    Shrini
    Participant


    {% 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 %}

    #28213
    Shrini
    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>

    #28214
    Shrini
    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 %}
    #28218
    Long Nguyen
    Moderator

    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.

    #28220
    Shrini
    Participant

    Thank you

    #28291

    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

    #28303
    Long Nguyen
    Moderator

    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>

    #28305

    Off course !
    Thx a lot Long 😉

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.