Display MB View shortcode in an Elementor loop template

Support MB Elementor Integrator Display MB View shortcode in an Elementor loop templateResolved

  • This topic has 4 replies, 2 voices, and was last updated 1 year ago by DufflDuffl.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #44328
    DufflDuffl
    Participant

    Hi, is that possible?

    I am trying to display MB View shortcode in an Elementor loop template.

    The aim is: I want to display posts in a loop, there display custom fields (works well) - and I want to display fields of connected relationships as well in that loop. This I cannot get to work.

    However, in a normal single post I can display relationships very well, works great. Just when I input the exact same code in a loop template it stops.

    Can this be done or is it impossible?

    #44339
    PeterPeter
    Moderator

    Hello,

    It is possible to use MB View shortcode to get the relationship of the post, add the View shortcode to the loop item and show related posts. You can use the WordPress function get_the_ID() to get the post ID of the current post in the loop. Then get the relationship based on the post ID.

    For example: I have a relationship between 2 CPT: from Post to My Job, relationship ID post-to-job and I'm using the Elementor widget Loop Grid to show a list of posts and related job posts. The sample View code:

    {% set current_post_id = mb.get_the_ID() %}
    
    {% set args = { post_type: 'my-job', relationship: { id: 'post-to-job', from: current_post_id } } %}
    {% set job_posts = mb.get_posts( args ) %}
    {% for job_post in job_posts %}
      Related Job: {{ job_post.post_title }} <br />
    {% endfor %}
    #44360
    DufflDuffl
    Participant

    Yessssssss this works 🙂 🙂

    Thank you Peter!

    I am happy to have set up my infrastructure on MetaBox. Great!

    #45022
    DufflDuffl
    Participant

    Hi I have a new question about this

    I am trying to use above code to display a list of post titles within that relationship. This works well - with only one issue: It will only display 5 related post titles. However there are more than 5 in the relationship.

    I have not been able to find out why not all of them will be shown.

    Do you know of any reason why it would only display 5?
    Thank you!

    #45097
    DufflDuffl
    Participant

    Solved here https://support.metabox.io/topic/for-loop-iterates-only-5-times-but-there-are-more-items-than-5/?swcfpc=1

    So my last post (#45022) can be ignored 🙂

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