Custom Fields
Re-Envisioned
Support MB Views Restrict post id queries in MB Views shortcode?

  • Creator
    Topic
  • #29387
    Viktor
    Participant

    Hi,
    I want to make a table using MB Views pulling custom fields (rows) from a custom post type (columns). Then the shortcode will be used in Gutenberg.

    I want to be able to restrict which posts it pulls though every time the shortcode is used. Can I pass arguments to the shortcode, say the post ids to use, so it only shows these products on that page rather then all?

    How could I filter/restrict post ids otherwise without creating new Views every single time?

    Many thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #29392
    Long Nguyen
    Moderator

    Hi Viktor,

    You just need to assign the Type to Shortcode. Then each time you add the shortcode in a post, the helper function rwmb_meta() will take the current post/page ID to pass to the third argument

    {{mb.rwmb_meta( 'field_id' )}}

    Get more details on the documentation https://docs.metabox.io/rwmb-meta/#arguments

    #29395
    Viktor
    Participant

    Hi Long,
    Thanks for the reply. Perhaps I wasn’t clear.
    I want to have a table like this - link but allow the the user to manually select which posts to compare. I was thinking of this working through a modified shortcode but maybe I can set a clonable dropdown field to select the table columns which MB Views then cycles through and pulls. What do you think?
    Thanks

    #29407
    Long Nguyen
    Moderator

    Hi Viktor,

    I think the custom data in the documentation can help you to do this job. Shortcode in the post

    [mbv id="your-view-id" my_post_id=102]
    

    get the field value of the post ID 102 in the View

    {{ mb.rwmb_meta( 'field_id', '', my_post_id ) }}
    

    Read more on the documentation https://docs.metabox.io/extensions/mb-views/#custom-data

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