Order relationship Options by ASC

Support MB Relationships Order relationship Options by ASC

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #35815
    YasmineYasmine
    Participant

    Hello, my relationship choices are showing the order that they were added, rather than alphabetical. I have tried to orderby but not working. How do I make the relationship options orderby ASC post-title, and what and where do I add this into the relationship settings? Cheers

    #35818
    Long NguyenLong Nguyen
    Moderator

    Hi,

    There is an issue with the setting query_args of the relationship, it is fixed in this commit https://github.com/wpmetabox/mb-relationships/commit/7e9505be0b3fc2ac69a1fc1ffba714cb4ede41f8

    You can download this branch to your site and follow the documentation to use the query_args with coding
    https://docs.metabox.io/extensions/mb-relationships/#using-code

    MB_Relationships_API::register( [
        'id'   => 'job-to-post',
        'from' => [
            'object_type'  => 'post',
            'post_type'    => 'job',    
            'field' => [
                'query_args' => [
                    'orderby' => 'title',
                    'order' => 'ASC'
                ]
            ]    
        ],
        'to'   => [
            'object_type'  => 'post',
            'post_type'    => 'post',
            'field' => [
                'query_args' => [
                    'orderby' => 'title'
                ]
            ]
        ],
    ] );
    #35836
    YasmineYasmine
    Participant

    Thank you Long!

    And sorry for being a newbie, but I added the 'commit' to my php files and changed the orderby to just 'title' in the relationship query_args. But it didn't work. Did I do what you suggested correctly?

    #35848
    Long NguyenLong Nguyen
    Moderator

    Hi,

    It works as well on my local site, please check this screen record https://monosnap.com/file/33zS6ArE3QpKkSKAC2m06os1nYlpvJ

    #36408
    YasmineYasmine
    Participant

    Hi Long,

    Still can't get this one working. I think that I did not get the commit working, as the php code does not look right:

    <?php
    add_action( 'mb_relationships_init', 'your_prefix_function_name' );
    
    function your_prefix_function_name() {
        MB_Relationships_API::register( [
            'id'   => 'university_user',
            'from' => [
                'object_type' => 'post',
                'post_type'   => 'university',
                'field'       => [
                    'query_args' => [
                        '5w1x2lx5oq7' => [
                            'id'    => '5w1x2lx5oq7',
                            'key'   => 'orderby',
                            'value' => 'title',
                        ],
                        'og7o0qgfecd' => [
                            'id'    => 'og7o0qgfecd',
                            'key'   => 'order',
                            'value' => 'ASC',
                        ],
                    ],
                    'max_clone'  => '1',
                ],
            ],
            'to'   => [
                'object_type' => 'user',
                'post_type'   => 'post',
                'taxonomy'    => 'category',
                'field'       => [
                    'query_args' => [
                        'iqoxqzev60p' => [
                            'id'    => 'iqoxqzev60p',
                            'key'   => 'orderby',
                            'value' => 'title',
                        ],
                        'mo9n62730iq' => [
                            'id'    => 'mo9n62730iq',
                            'key'   => 'order',
                            'value' => 'ASC',
                        ],
                    ],
    #36422
    Long NguyenLong Nguyen
    Moderator

    Hi,

    This issue has been fixed in the new version of MB Builder, MB AIO. You can remove the code in that commit, update the extension and re-check the issue.

    #36429
    YasmineYasmine
    Participant

    Thanks Long, I am up to date with the latest MB AIO - but still face the same issue. I have tried to delete re-add etc..

    Currently I am just adding orderby and order into the query_args on the relationship. I have also additionally added it into settings in custom fields. But with this too, it still is not working.

    Is there something I am missing? Or could I have a setting that is overwriting this?

    Many thanks!

    #36444
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can try to switch to the standard theme of WordPress (Twenty TwentyTwo) and deactivate all plugins except Meta Box, MB extensions then recheck this issue. See how it works on my end https://monosnap.com/file/As4Qk5fWuYQzLgPI1DMBgOeqUeC7ev

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