Get Post Taxonomy Slug

Support MB Views Get Post Taxonomy SlugResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #19661
    Trang NguyenTrang Nguyen
    Participant

    Hi!
    Please help me with 2 questions in Views:

    1. How to get Taxonomy Slug of a Custom Post Type /Post (raw data)?
    2. If a post is assigned to more than 1 taxonomy item, get only the first slug.

    Many thanks!

    #19664
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can use the option Post term list to show the listing term of the post in the tab Post, see my screenshot https://share.getcloudapp.com/z8ux9Oyg

    Or use the function get_the_terms() via mb proxy to show the slug of the first term, here is the sample code

    {% set termList = mb.get_the_terms( post.ID, 'category' ) %}
    {{ termList[0].slug }}

    For more information, please follow the documentation.
    https://developer.wordpress.org/reference/functions/get_the_terms/

    #19674
    Trang NguyenTrang Nguyen
    Participant

    Thank you very much, Long! It works 100%!

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