Taxonomy (Author) fields not showing on Custom Post Type preview

Support MB Views Taxonomy (Author) fields not showing on Custom Post Type preview

  • This topic has 3 replies, 2 voices, and was last updated 1 year ago by PeterPeter.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #45045
    BBBB
    Participant

    I followed everything in the Getting Started part of the manual. I created a custom post type 'Book', a taxonomy 'Author', and two custom field sets (one for Author, one for Book). I've created a View, but the Author fields are not shown, the field for the book are shown correctly.

    See images here: https://imgur.com/a/gcfeGry

    What could be the issue?

    #45053
    PeterPeter
    Moderator

    Hello,

    The author won't show because you are in the main query of the post so the post properties will work like post.ID, post.title ...

    If you want to get the taxonomy and custom fields (term meta) of the current post, you should use the WordPress function get_the_terms() to get the author and helper function rwmb_meta() to get the author custom fields.

    Please follow the documentation
    https://docs.metabox.io/extensions/mb-views/#main-query
    https://docs.metabox.io/extensions/mb-views/#running-php-functions
    https://docs.metabox.io/extensions/mb-term-meta/

    #45311
    BBBB
    Participant

    Dear Peter, I've tried various things, but this is all new for me and I can't seem to get it working... Perhaps you see something obvious that I'm overlooking?

    This is the code now that I'm trying...

    {% set term = mb.get_the_terms(post.ID, 'writer') %}

    {% set postauthor = mb.rwmb_meta( writer_first_name, '', term.ID ) %}
    <p>
    Author: {{ postauthor }}
    </p>

    #45322
    PeterPeter
    Moderator

    Hello,

    The function get_the_terms() returns an array of terms, you should use the loop to iterate through the array to get each term ID.
    Also, you should use the single quote to wrap the field ID in the helper function and use the second parameter to get the term meta.
    rwmb_meta( 'writer_first_name', { object_type: 'term' }, term.ID )

    Following the documentation https://docs.metabox.io/extensions/mb-term-meta/

    If you cannot complete the task, we offer a customization service with an extra fee. You can submit the contact form with the details, our development team will get in touch with you shortly.
    https://metabox.io/contact/

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