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

  • Creator
  • #29387

    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
  • #29392
    Long Nguyen

    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


    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?

    Long Nguyen

    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

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