Display a link from a relation

Support MB Views Display a link from a relation

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #37317
    info@ceescoenen.nl[email protected]
    Participant

    I have this code:

    {% set args = { post_type: 'bepakking', posts_per_page: -1, tax_query: [{
           'taxonomy': 'Rubriek',
           'field': 'slug',
           'terms': 'kleding'
          }]} %}
    {% set posts = mb.get_posts( args ) %}
    
    Aantal stuks: {{ posts|length }} 
    {% for post in posts %}
    <li>
    {{ post.title }}
    </li>
    {% endfor %}

    It displays all the post in the CPT. Some posts has a relation to another post (other CPT). How can I display a link to that post when there is a relation?

    #37323
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can just create a nested loop inside the current loop to get and display the relation posts. Refer to this topic https://support.metabox.io/topic/query-in-relationship-post-per-page/#post-29149

    {% for post in posts %}
    {{ post.title }}
    	{% set args2 = { ... } %}
    	{% set posts2 = mb.get_posts( args2 ) %}
    	{% for post2 in posts2 %}
    		{{ post2.title }}
    	{% endfor %}
    {% endfor %}
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.