How to sort returned posts on CF day if selected posts are for CF month

Support MB Views How to sort returned posts on CF day if selected posts are for CF monthResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #47629
    Eddy HoogendijkEddy Hoogendijk
    Participant

    I want to show all members that have their birthday this month (February).
    They are all shown, but not in the proper order of the day. It seems really random.

    This is the code I have: (verjaardag=birthday, dag=day, maand=month)

    <h3>FEBRUARI</h3>
    {% set args = {  meta_key:'verjaardag_maand', meta_value:'2', posts_per_page: -1, orderby: { meta_key: 'verjaardag_dag', meta_value_num: 'verjaardag_dag'}, order: 'asc' } %}
    {% set users = mb.get_users( args ) %}
    {% for user in users %}
        {{ user.verjaardag_dag }} Februari: {{ user.display_name }}
    
    {% endfor %}

    I can't figure out how to set the orderby properly.

    #47634
    PeterPeter
    Moderator

    Hello Eddy,

    The parameter meta_key doesn't exist under the parameter orderby when you use the function get_users(). Following the WordPress documentation
    https://developer.wordpress.org/reference/classes/wp_user_query/#order-orderby-parameters

    You can try to use this query args

    {% set args = {  
        meta_query: [
            { key: 'verjaardag_maand', value: '2', compare: '=' }
        ],
        meta_key: 'verjaardag_dag', 
        orderby: 'meta_value_num', 
        order: 'asc',
        posts_per_page: -1
    } %}
    
    {% set users = mb.get_users(args) %}
    

    or ask about the user query args in the WordPress support forum https://wordpress.org/support/forum/how-to-and-troubleshooting/

    #47641
    Eddy HoogendijkEddy Hoogendijk
    Participant

    Hi Peter,

    That worked. Thanks a lot!

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