I have registered a rest field in my functions.php for the API to show:
It is showing the result correctly, now I want a custom endpoint API which I created to sort the result by the number of views from higher to lower from 2 days ago. This is the code:
For the action:
and this is the function:
The function is also working fine but the issue is that it is only taking the number of views and arranging it from 999 and backwards. I have posts which have thousands of views but it is not fetching those results. I would appreciate any help.