We would like to sort our Job Ads and Nanny Ads by Last Modified instead of Post Date. I saw several posts on the forum regarding the topic and tried a few things but I still can't get the Views to display by Last Modified instead of Post Date.
1) In the Views "Find a Native Nanny Search and Results View" and "Find a Job Search and Results View", I have set "Order by" to Last Modified Descending but both Views are still ordering by Post Date Descending.
2) What would be the correct syntax for the ORDER BY [wpv-sort-orderby] criteria for Last Modified date? As an example in the Loop Editor of the View "Find a Native Nanny Search and Results View", I tried to use the syntax post_date type='modified' instead of just post_date
Thanks for the update. It seems to be sorting correctly by Last Modified if I actively choose it from list of options, but the list of options still contains Post Date when you first call up the page hidden link , although it is not listed in the orderby select (see screenshot).
When I change the SORT BY to Last Modified, the list refreshes correctly, then "Post Date" is no longer selectable from the list (as required), but why is Post Date still an option there when you go open the page Find a Native Nanny? I tried clearing my browser cache in case it was that, but it is still there after clearing that too.
I see the option removed, however the sorting is still defaulting to Post Date Descending in the background. When a user first goes to Find a Native Nanny, the list is is still being shown by Post Date Descending, although the SORT BY list is showing Last Modified Descending. In order to get the list to be truly Last Modified Descending, the user would have to actively choose another sorting rule, (eg change to Ascending), and then choose Last Modified Descending to get the list as required.
In other words, the Last Modified Descending is not the default sort order, as required, and is currently visible in the SORT BY.
As a workaround to set default post orderby to modified date, I've added the following view's filter hook to "Custom Code" section of Toolset with code snippet namely "set-orderby-modified"
=> hidden link
Can you please contact your devs and ask for an approximate indication of when the bug will be fixed? Weeks/months? Has it reached QA stage yet?
I would like to avoid Custom Code where at all possible, however I understand it is unavoidable in some cases.
Regarding your last piece of code (in case the bug is not fixed for a while):
1) What are the numbers 101, 3 at the end of your code for?
2) If we are not using AJAX, can we just drop this in the code? and !wp_doing_ajax()
3) What would be the syntax to add other views into this code, so we don't have to write a new piece of code for every view which has the bug?
There is no ETA on when the fix is provided as the issue is just reported and our Devs take care of it as its totally depends on their pre-defined priority and work.
Regarding your last piece of code (in case the bug is not fixed for a while):
1) What are the numbers 101, 3 at the end of your code for?
==>
The 101 is the hook priority and 3 is the number of argument you will pass to the function.
More info:
- https://developer.wordpress.org/reference/functions/add_filter/
2) If we are not using AJAX, can we just drop this in the code? and !wp_doing_ajax()
===>
If you drop ajaxt, the code needs to be again adjusted in the case of not using AJAX.
3) What would be the syntax to add other views into this code, so we don't have to write a new piece of code for every view which has the bug?
===>
To apply multiple view IDs the code should be adjusted as given under:
Where:
- You can adjust your multiple target view IDs with $target_view_ids array. Where 999 and 222 I've added as dummy view IDs for the example purpose.
OK, I have modified the code for the 2 views. It appears to be working as we need it, but could I ask you to just have a quick look at the code to verify it? I just added the other view to the array and removed the AJAX part.
If the code is OK, our issue is temporarily resolved with a workaround. I would prefer to keep the ticket open until the underlying bug is resolved. Please set it to "Escalated to 2nd tier" like our other open bugs and send us a quick update when the underlying bug with Post Date has been fixed.
As you drop AJAX part, the sorting is not triggeted. Please set your view to use the AJAX and as before and use the code I shared with above reply (for which I shared the link) and just replace view IDs within the code.
We have to live without AJAX for the moment. I dropped the AJAX part because when we use AJAX the search results are not inconsistent due to translation issues with WPML. We have another ticket open about that.