How to show relationships in same order as set in backend?

Support MB Views How to show relationships in same order as set in backend?

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #46102
    EddyPiVEddyPiV
    Participant

    Hi, in the admin area I can drag and drop the order of the chosen items of the relationship. That's nice.

    But how do I show that same order in the frontend?

    The closest I saw in get_posts is orderby:'none', but it doesn't help.

    So is there a way to show in frontend the same order as in backend?

    #46108
    PeterPeter
    Moderator

    Hello Eddy,

    The order of relationship items in the front end will display the same order as in the admin area. Can you share some screenshots of the issue and the code that you use to output the relationship?

    #46111
    EddyPiVEddyPiV
    Participant

    Peter, this is the code for the page.

    {% set args1 = { post_type: 'repetitie-avond', posts_per_page: -1, orderby: 'date', order: 'asc' } %}
    {% set posts = mb.get_posts( args1 ) %}
    
    {% for post in posts %}
        <h2><strong>{{ post.title }}</strong></h2>
        <p>{{ post.content }}</p>
        {% set args2 = {post_type: 'muziek', nopaging: true, orderby:'none', relationship: {id: 'muziek-op-repetitie-avond', from: post.ID}} %}
        {% set muzieknummers = mb.get_posts( args2 ) %}
    
        {% set counter = 0 %}
        {% for muziek in muzieknummers %}
            {% set counter = counter +1 %}
            {% set post2 = mb.get_post( muziek.ID ) %}
            <p><a href="{{ post2.url }}">{{ post2.post_title }}</a></p>
        {% endfor %}
    
        {% if  counter == 0 %}
            Er is nog geen muziek voor deze avond vastgelegd. - no music yet - 
        {% endif %}
    <hr />
    {% endfor %}

    Here is a short video of all settings involved: https://drive.google.com/file/d/1Ok9HploeRIkomw7uukIa7cuikxAFH1gN/view?usp=drive_link

    Regards,
    Eddy

    #46116
    PeterPeter
    Moderator

    Hello,

    You are using the parameter orderby:'none' so the relation posts will be displayed with no order. Please remove it and check the issue again.

    #46119
    EddyPiVEddyPiV
    Participant

    Peter,

    If I do that, they are shown in descending order of title, that's not the order in the backend.
    That's why I tried orderby: none, hoping that it would result in the order of the backend, but it didn't work. That's exaclty why I started this thread.

    So any advise?

    #46128
    PeterPeter
    Moderator

    Please remove the order parameter from both args1 and args2 then check the issue again. If it still doesn't work, you can share your admin account by submitting this contact form https://metabox.io/contact/
    I will take a look.

    #46131
    EddyPiVEddyPiV
    Participant

    Peter, it didn't make a difference, so I've set up an admin account for you, and sent the login credentials as requested.

    Thanks, good luck.

    #46135
    EddyPiVEddyPiV
    Participant

    Peter, fyi:
    I did a complete plugin conflict test with theme Twenty Four, and still the same.

    Looking forward to your advise.

    #46315
    MKDevMKDev
    Participant

    @EddyPiV @Peter

    Still no solution for this?

    I am using Oxygen and also want the related entries in the order the user drags them in the backend.
    I used advanced query builder and only args are post_type, post__in and no_found_rows (true).

    #46316
    MKDevMKDev
    Participant

    Solution for oxygen query builder (can't Edit):

    order by relationship

    oderby
    array ---> [key -> post__in] [value -> ASC]

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