Conditional rendering based on the post type

Support MB Views Conditional rendering based on the post typeResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #36933
    ArnoArno
    Participant

    Hi,

    Inside a view, how to I create a condition based on the post type?

    I was thinking a Twig snippet like this?

    {% if post.type == 'blog' %}
    {% endif %}

    But the property "type" is not the right one. Nor is "slug", that gets me the slug of the individual post. I need the slug of the post type basically.

    #36946
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Please use the property post_type to get the post type of a post object.

    Post type: {{ post.post_type }}

    Read more on the documentation https://developer.wordpress.org/reference/classes/wp_post/

    #36947
    ArnoArno
    Participant

    Thank you Long, that solves this.

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