Rendering a Custom Post type Loop in Gutenberg using a shortcode

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

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #27538
    Cody SmithCody Smith
    Participant

    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?

    #27559
    Long NguyenLong Nguyen
    Moderator

    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.

    #27573
    Cody SmithCody Smith
    Participant

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

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