CPT url not working in MB View

Support MB Views CPT url not working in MB ViewResolved

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #28211
    ShriniShrini
    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 %}

    #28212
    ShriniShrini
    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
    ShriniShrini
    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
    ShriniShrini
    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 NguyenLong 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
    ShriniShrini
    Participant

    Thank you

    #28291
    philippe@studiocassette.com[email protected]
    Participant

    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 NguyenLong 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
    philippe@studiocassette.com[email protected]
    Participant

    Off course !
    Thx a lot Long 😉

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