Custom Fields
Re-Envisioned
Support MB Views View: Permalink for CPT

  • Creator
    Topic
  • #32884
    Resolved goninski@gmail.com
    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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #32891
    Long 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
    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 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 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.