View: Permalink for CPT

Support MB Views View: Permalink for CPTResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #32884
    goninski@gmail.com[email protected]
    Participant

    Hello

    This is simple post listing for a cpt which basicly works.

    
    {% set args = { post_type: 'fg-dev', posts_per_page: -1 } %}
    {% set posts = mb.get_posts( args ) %}
    {% for post in posts %}
    <ul>
        <li style="line-height: 1";><a href="{{ post.post_url }}">{{ post.post_title }}</a></li>
    </ul>    
    {% endfor %}
    

    The only thing not working is the permalink. The expressions <post.post_url> or <post.post_slug> and many others I tried do not work. What is the right expression for this and where can find this on the internet? I was not able to find this.

    Thanks in Advance for your help
    François

    #32891
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You are using the custom query, please use the WordPress function get_the_permalink() to get the permalink. For example:

    <a href="{{ mb.get_the_permalink( post.ID ) }}">{{ post.post_title }}</a>
    

    Refer to this documentation https://docs.metabox.io/extensions/mb-views/#custom-query

    #32899
    goninski@gmail.com[email protected]
    Participant

    Hi
    Thanks for the snippet. It works now.
    But I do not understand why for this custom query in one case I need to use the wp function and in other cases not (eg. post.post_title)? Is there a simple answer?

    Thanks

    #32904
    Long NguyenLong Nguyen
    Moderator

    Hi,

    As you can read on the documentation https://docs.metabox.io/extensions/mb-views/#custom-query

    the function get_posts() or get_post() returns the post object and it does not include the permalink or URL of the post. So we can use WP function get_the_permalink() to get post permalink based on the post ID.

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