Custom Fields
Support MB Views Rendering a Custom Post type Loop in Gutenberg using a shortcode

  • Creator
  • #27538
    Resolved Cody Smith

    I'm a beginner and likely approaching this all wrong, but I have a custom post type called "Food Menu Items". I want to output the Title/Content of each CPT on a different PAGE using a shortcode inside the standard Gutenberg/block editor.

    Here's the code I've added to the Metabox Views Template area:

    {% set args = {post_type: 'food-menu-item', %}
    {% set menuitems = mb.get_posts( args ) %}
    {% for menuitem in menuitems %}
        <h4>{{ menuitem.post_title }}</h4>
    {% endfor %}

    I've set the "Type" to shortcode, and published the View. After adding the shortcode to the page using the shortcode block, I'm getting this error and can't save the page:

    "Updating failed. The response is not a valid JSON response."

    Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
  • #27559
    Long Nguyen

    Hi Cody,

    Your code is missing the closing curly bracket } of the args variable

    {% set args = {post_type: 'food-menu-item'} %}

    Please add it and re-check the issue.

    Cody Smith

    Ha, I knew it had to be something silly that I was overlooking. That worked perfectly. Thanks so much!

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