Ordering Items in a Select Advanced Field

Support MB Views Ordering Items in a Select Advanced Field

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36480
    nathan@brilliantly.net[email protected]
    Participant

    I'm stuck.
    Post Type: Team
    Custom Field: team_program_affiliations (post field -- select advanced)

    I started with this view:

    {% for item in post.team_program_affiliations %}
    	<a class="fl-button program-button" href="{{ item.url }}">{{ item.title }}</a>
    {% endfor %}

    It works. But it shows the post titles (which are item.title). But they are in DESC order. I have to get them to appear in ASC order. I have tried following the documentation here (https://docs.metabox.io/extensions/mb-views/#custom-query). However, I can't get it to work.

    This is the last thing I have tried in the view:

    {% set args = { post_type: 'team', posts_per_page: -1, orderby: 'item.title', order: 'ASC', meta_key: 'team_program_affiliations' } %}
    {% set post = mb.get_posts( team ) %}
    {% for item in post.team_program_affiliations %}
    	<a class="fl-button program-button" href="{{ item.url }}">{{ item.title }}</a>
    {% endfor %}

    Could you help me understand how to apply an order to the item.title? Thanks so much.

    #36492
    Long NguyenLong Nguyen
    Moderator

    Hi,

    To order by title, please just use this code orderby: 'title'
    Refer to this topic https://support.metabox.io/topic/how-to-order-sort-related-posts-by-title-or-custom-field-value/
    and this documentation https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters

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