• Resolved CHEWX

    (@chewx)


    Hi,

    Usually you can use ?orderby=menu_order, however you cannot do this with the media endpoint.

    As such, could you expose the order to the media endpoint so I can do this manually as it doesn’t actually show “order” anywhere, but you must save it somewhere.

    Thanks,
    Tom

Viewing 1 replies (of 1 total)
  • Plugin Author webbistro

    (@webbistro)

    Hi Tom,

    It seems to be a WP core issue, I need more time to test and offer a built-in solution. Right now I found this https://stackoverflow.com/questions/54260699/ordering-by-menu-order-in-the-wordpress-rest-api

    So, adding the filter like this:

    // Add menu_order as an option for orderby param in REST API for attachment post type
    add_filter( 'rest_attachment_collection_params', 'my_prefix_add_rest_orderby_params', 10, 1 );
    
    function my_prefix_add_rest_orderby_params( $params ) {
        $params['orderby']['enum'][] = 'menu_order';
    
        return $params;
    }

    worked for me with this:

    /wp-json/wp/v2/media?orderby=menu_order&order=asc

    Best,
    -Nadia

Viewing 1 replies (of 1 total)
  • The topic ‘Order into REST API’ is closed to new replies.