Set the post ID in a view

Support MB Views Set the post ID in a viewResolved

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #28801
    gbreen@scopedesign.com[email protected]
    Participant

    I am trying to create a view from a post with sections and pages that are clonable. Below you can see the view I am starting to make. You can see here
    {% set post = mb.get_post( the_post_id ) %}
    the post id is being set via a function in this case its 16. Some fields show properly {{ clone.section_name }} and {{ clone.page_name }} work fine. {{ clone.page_name }} does not work.

    If I do not use the short code and just show the page removing

    {% set the_post_id = mb.get_pid() %}
    {% set post = mb.get_post( the_post_id ) %}

    it all works.

    Ultimately how can I set the post I want the view to show if I use the shortcode?

    Menu
    {# 
    Get the post id
    mb.get_pid() is pulling from a function set in snippits
    #}
    {% set the_post_id = mb.get_pid() %}
    {% set post = mb.get_post( the_post_id ) %}
    
    {# Build the menu #}
    {% for clone in post.section %}
        {{ clone.section_name }}
        {% for clone in clone.page %}
            {{ clone.page_name }}
            {{ clone.post.title }}
        {% endfor %}
    {% endfor %}
    #28830
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Thank you for getting in touch.

    If you use the field post to select a page and save it as the custom field of a post, please use the WordPress function to get the page title. Get more details here https://docs.metabox.io/extensions/mb-views/#running-php-functions

    You can also share the code that creates the custom fields, I will help you to check the code.

    #28842
    gbreen@scopedesign.com[email protected]
    Participant

    I'm all good. I ended up just using php to make the view. There were just to many places that were taking to long to do in the view. It may be possible I just ran out of time to play.

    #28844
    Long NguyenLong Nguyen
    Moderator

    Let me know if you have any questions.

    #30051
    info@cybercore.de[email protected]
    Participant

    The same point here. Did you find out how to pass a post id into the shortcode for viewing the complete post for this id?

    #30073
    Long NguyenLong Nguyen
    Moderator

    Hi @cybercore,

    You can follow this documentation to know how to pass data (post ID) to the shortcode via custom attributes https://docs.metabox.io/extensions/mb-views/#custom-data

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